Completed
Last Updated: 13 Mar 2014 10:54 by ADMIN
ADMIN
Georgi I. Georgiev
Created on: 15 Nov 2013 01:49
Category: GridView
Type: Bug Report
2
IMPROVE. RadGridView - add overload for BestFitting a column considering all cells
To reproduce:
Add a RadGridView wth a few columns ,add rows as a few rows should have increasingly long text. Right click on the header cell to show the context menu and click bestfit. You will notice that the size of the column is not correct

Workaround: void grid_MouseMove(object sender, MouseEventArgs e) { this.mouseLocation = e.Location; } private Point mouseLocation; private GridViewColumn currentColumn; void grid_ContextMenuOpening(object sender, ContextMenuOpeningEventArgs e) { if (this.grid.CurrentRow is GridViewHierarchyRowInfo) { RadItem bestFitItem = e.ContextMenu.Items.FirstOrDefault(x => x.Text == "Best Fit"); if (bestFitItem != null) { e.ContextMenu.Items.Remove(bestFitItem); } RadMenuItem newBestFitItem = new RadMenuItem { Text = "Best Fit" }; this.currentColumn = (this.grid.ElementTree.GetElementAtPoint(this.mouseLocation) as GridCellElement).ColumnInfo; newBestFitItem.Click += newBestFitItem_Click; e.ContextMenu.Items.Add(newBestFitItem); } } void newBestFitItem_Click(object sender, EventArgs e) { int highestWidth = this.GetHeightestWidthFromColumn(this.currentColumn); this.currentColumn.Width = highestWidth; } private int GetHeightestWidthFromColumn(GridViewColumn gridViewColumn) { int max = int.MinValue; Font cellFont = this.grid.TableElement.VisualRows[0].VisualCells[0].Font; for (int i = 0; i < this.grid.Rows.Count; i++) { int textWidth = TextRenderer.MeasureText(this.grid.Rows[i].Cells[gridViewColumn.Index].Value + "", cellFont).Width; if (max < textWidth) { max = textWidth; } } return max; }
1 comment
ADMIN
Ralitsa
Posted on: 13 Mar 2014 10:53
Resolution:
The described scenario is not an issues. Each column has AutoSizeMode property which controls how the column will adjust its width after BestFit is executed.  Default value of this property is "DisplayedCells" due performance reasons. However, to achieve the desired behavior just change the value of AutoSizeMode property to "AllCells".