|
Query |
Response |
|
1. Is this the correct way? Or is there a better way to change the row Height? |
In the provided code example, you have modified the font size after resizing the rows and columns. So that, the Rows and Columns will be resized based on the previous font size. In order to resize the RowHeightsand ColumnWidths when font size is changed, the ResizeToFit() method can be called after the font size is modified. We have modified the provided code part and created a simple sample as per your scenario. Please make use of below code and sample,
Code example
private static void ChangeControlFont(GridGroupingControl grid, float fontSize, string fontName)
{
grid.Appearance.ColumnHeaderCell.Font.Size = fontSize;
grid.Appearance.AlternateRecordFieldCell.Font.Size = fontSize;
grid.Appearance.RecordFieldCell.Font.Size = fontSize;
grid.Appearance.FilterBarCell.Font.Size = fontSize;
grid.GridGroupDropArea.Model.BaseStylesMap.Standard.StyleInfo.Font = new GridFontInfo(newFont(fontName, fontSize));
//To resize the RowHeights and ColumnWidths
grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table(),GridResizeToFitOptions.IncludeHeaders);
grid.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Table(),GridResizeToFitOptions.IncludeHeaders);
}
|
|
2. What is the difference between ScrollableGridRangeInfo and GridCellsRange? Their descriptions are the same |
As per the GridGroupingControl current architecture, the ScrollableGridRangeInfo contains the cells which are non-frozen (i.e. the cells excluding Row/Column header, FilterBarCells, IndentColumn, CaptionRow, AddNewRecord row and the frozen row and column.) whereas, the GridCellsRange contains all the cells except Row/Column header cells. |
|
3. When run on a large grid is takes some time to be applied. Is there any way to improve performance? |
The ScrollableGridRangeInfo calculates the height of rows and width of columns for all the scrollable cells when ResizeToFit() is called. Moreover, while calculating the width/height of cells, the length of the cell values of each cell are computed and the width/height are modified. So, the grid will take some to loop through the records and calculate the height/width when the grid has more records. To improve the performance, we could suggest you to resize the cells/rows/table of GridRangeInfo based on requirement. So that, the calculation of width/height will be computed based on the cells. Please refer to the below code,
Code example
//To resize the RowHeights and ColumnWidths
grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Table(),GridResizeToFitOptions.IncludeHeaders);
grid.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Table(),GridResizeToFitOptions.IncludeHeaders);
|
|
4. When I change to a large font the font enlarges until there is no top or bottom margin. But some columns still display the top margin. How can i disable the top and bottom margins for all columns? |
By default, the font will be updated based on the font size and the cell values will be wrapped if the cell values exceed the cell boundaries. Moreover, the Borders will be drawn for all the cells though the font size is changed. We suspect that you are changing the borders of the cells based on font size of the cells. So that, the reported issue might be occurred. So, we request you to refer the attached sample and let us know that, if we missed anything from your customization which causes the issue. So that, we could analyze further to provide you a better solution at the earliest. |
|
5. The same applies for small fonts. The text is smaller but the top and bottom margin negates this as a lot of 'empty' space is displayed and wasted. |
|
//To reduce the border margins
grid.Appearance.AnyCell.BorderMargins.Top = 0;
grid.Appearance.AnyCell.BorderMargins.Bottom = 0;
|
|
//To reduce the text margins
grid.Appearance.AnyCell.TextMargins.Top = 0;
grid.Appearance.AnyCell.TextMargins.Bottom = 0;
|
|
#region //To reduce the border and text margins
grid.Appearance.AnyCell.BorderMargins.Top = 0;
grid.Appearance.AnyCell.BorderMargins.Bottom = 0;
grid.Appearance.AnyCell.TextMargins.Top = 0;
grid.Appearance.AnyCell.TextMargins.Bottom = 0;
#endregion
//To resize the RowHeights and ColumnWidths only based on the cells height
grid.TableModel.RowHeights.ResizeToFit(grid.TableModel.GridCellsRange);
grid.TableModel.ColWidths.ResizeToFit(grid.TableModel.GridCellsRange); |
|
//To resize the RowHeights for column header row
grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Cells(grid.TableControl.TopRowIndex - 1, 1, grid.TableControl.TopRowIndex - 1, grid.TableDescriptor.Columns.Count));
//To resize the RowHeights for grid table range
grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Cells(grid.TableControl.TopRowIndex,1, grid.Table.Records[1].GetRowIndex(), grid.TableDescriptor.Columns.Count));
//To resize the column widths
grid.TableModel.ColWidths.ResizeToFit(grid.TableModel.ScrollableGridRangeInfo, GridResizeToFitOptions.IncludeHeaders); |
|
private static void ChangeControlFont(GridGroupingControl grid, float fontSize, string fontName)
{
grid.Appearance.ColumnHeaderCell.Font.Size = fontSize;
grid.Appearance.AlternateRecordFieldCell.Font.Size = fontSize;
grid.Appearance.RecordFieldCell.Font.Size = fontSize;
grid.Appearance.FilterBarCell.Font.Size = fontSize;
grid.GridGroupDropArea.Model.BaseStylesMap.Standard.StyleInfo.Font = new GridFontInfo(new Font(fontName, fontSize));
grid.Appearance.AnyCell.TextMargins.Top = 0;
grid.Appearance.AnyCell.TextMargins = new GridMarginsInfo(0, 0, 0, 0);
//To resize the RowHeights for column header row
grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Cells(grid.TableControl.TopRowIndex - 1, 1, grid.TableControl.TopRowIndex - 1, grid.TableDescriptor.Columns.Count));
//To resize the RowHeights for grid table range grid.TableModel.RowHeights.ResizeToFit(GridRangeInfo.Cells(grid.TableControl.TopRowIndex,1, grid.Table.Records[1].GetRowIndex(), grid.TableDescriptor.Columns.Count));
//To resize the column widths
grid.TableModel.ColWidths.ResizeToFit(grid.TableModel.ScrollableGridRangeInfo, GridResizeToFitOptions.IncludeHeaders);
//Get the cell renderer of a cell to get the text rectangle of the rows
GridTextBoxCellRenderer ren = grid.TableControl.CellRenderers["TextBox"] as GridTextBoxCellRenderer;
//To get the cell style
GridTableCellStyleInfo style = grid.TableControl.GetTableViewStyleInfo(grid.TableControl.TopRowIndex, 1);
//To get the cellLayout
GridCellLayout cellLayout = ren.GetCellLayout(grid.TableControl.TopRowIndex, 1, style);
//To remove the margins from the text rectangle to reset the row height
grid.TableOptions.RecordRowHeight = cellLayout.TextRectangle.Height - 2;
} |