/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the specified grid with values from the save layout information. /// </summary> /// ------------------------------------------------------------------------------------ public void InitializeGrid(DataGridView grid) { if (grid == null || grid.Columns.Count == 0 || _project == null) { return; } SilHierarchicalGridColumn.ShowHierarchicalColumns(grid, false, true, false); grid.CellBorderStyle = GridLines; // Set the column properties to the saved values. foreach (var col in grid.Columns.Cast <DataGridViewColumn>()) { var field = _project.GetFieldForName(col.Name); if (field == null) { continue; } if (field.DisplayIndexInGrid < 0) { col.Visible = false; } else { col.Visible = field.VisibleInGrid; col.DisplayIndex = (field.DisplayIndexInGrid < grid.Columns.Count ? field.DisplayIndexInGrid : grid.Columns.Count - 1); } } SilHierarchicalGridColumn.ShowHierarchicalColumns(grid, true, false, true); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Goes through each of the grid's rows and determines which field in those rows is /// the widest in the specified column. /// </summary> /// ------------------------------------------------------------------------------------ private void CalculateWidestColumnHeadingText(DataGridViewColumn column) { var field = m_project.GetFieldForName(column.Name); using (Font fnt = new Font(FontHelper.UIFont.FontFamily, kheadingFontSize, FontStyle.Bold, GraphicsUnit.Point)) { var text = new StringBuilder(column.HeaderText); // If the heading has a space in it, then insert a newline at the last // space and get the width necessary for the heading when it wraps on // the last word in the heading. if (m_exportFormat == ExportFormat.Table) { int i = column.HeaderText.LastIndexOf(' '); if (i > 0) { text[i] = '\n'; } } m_maxFieldWidths[column.Index] = TextWidthInTwips(text.ToString(), fnt); if (field.Type == FieldType.Phonetic) { m_phoneticColFont = field.Font; m_phoneticColIndex = column.Index; // If we're calculating the column width for the phonetic column and // it's for a search result word list, then add in the gap between the // preceding environment and the search item. if (m_cache.IsForSearchResults) { m_maxFieldWidths[column.Index] += kGapBetweenSrchItemAndPrecedingEnv; } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Makes the specified field the first, or primary, field on which to sort. /// </summary> /// ------------------------------------------------------------------------------------ public bool SetPrimarySortField(string newPrimarySortField, bool changeDirection) { return(_project != null && SetPrimarySortField(_project.GetFieldForName(newPrimarySortField), changeDirection)); }