Completed
Last Updated: 31 Mar 2014 09:22 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 14 Nov 2013 07:34
Category: GridView
Type: Bug Report
3
FIX. RadGridView does not set correct columns width of child template with BestFitColumns
To reproduce: - add RadGridView and populate manually with hierarchical data; 

- BestFitColumns method of the child template does not work as expected; 

#1 scenario: radGridView1.MasterTemplate.ExpandAll(); radGridView1.Templates[0].ExpandAll(); radGridView1.Templates[0].BestFitColumns(BestFitColumnMode.AllCells); You will notice that some of the columns in the child template are not wide enough to show the whole cell content; 

#2 scenario: Subscribe to the ChildViewExpanded event and call BestFitColumns: private void radGridView1_ChildViewExpanded(object sender, ChildViewExpandedEventArgs e) { e.ChildViewInfo.ViewTemplate.BestFitColumns(BestFitColumnMode.AllCells); } 

As a result the firstly expanded child view adjusts child template columns width and if you expand another child view which needs greater columns width, it is not displayed correctly. 

Workaround: determine the column width according to the longest cell content: foreach (GridViewDataColumn col in radGridView1.Templates[0].Columns) { BestFitAllCells(col); } private void BestFitAllCells(GridViewColumn column) { MasterGridViewTemplate masterTemplate = column.OwnerTemplate.Parent as MasterGridViewTemplate; if (masterTemplate == null) { return; } RadGridView grid = masterTemplate.Owner; IVirtualizedElementProvider<GridViewRowInfo> rowProvider = grid.TableElement.RowElementProvider; IVirtualizedElementProvider<GridViewColumn> cellProvider = grid.TableElement.ColumnScroller.ElementProvider; float width = 0; foreach (GridViewRowInfo dataRow in column.OwnerTemplate.Rows) { GridRowElement row = rowProvider.GetElement(dataRow, null) as GridRowElement; row.InitializeRowView(grid.TableElement); row.Initialize(dataRow); row.UpdateInfo(); grid.TableElement.Children.Add(row); row.ResetLayout(true); GridVirtualizedCellElement cell = cellProvider.GetElement(column, row) as GridVirtualizedCellElement; cell.Attach(column, row); cell.SetContent(); cell.UpdateInfo(); row.Children.Add(cell); GridHeaderCellElement headerCell = cell as GridHeaderCellElement; if (headerCell != null) { headerCell.UpdateArrowState(); } cell.ResetLayout(true); width = Math.Max(width, this.GetCellDesiredWidth(cell)); row.Children.Remove(cell); grid.TableElement.Children.Remove(row); this.Detach(cellProvider, cell); this.Detach(rowProvider, row); } width = Math.Max(width, TextRenderer.MeasureText(column.HeaderText, grid.Font).Width); column.Width = (int)width; } private float GetCellDesiredWidth(GridCellElement cell) { cell.Measure(new SizeF(float.PositiveInfinity, float.PositiveInfinity)); return cell.DesiredSize.Width; } private void Detach(IVirtualizedElementProvider<GridViewColumn> elementProvider, GridCellElement cell) { GridVirtualizedCellElement virtualizedCell = cell as GridVirtualizedCellElement; if (virtualizedCell != null) { elementProvider.CacheElement(virtualizedCell); virtualizedCell.Detach(); return; } cell.Dispose(); } private void Detach(IVirtualizedElementProvider<GridViewRowInfo> elementProvider, GridRowElement row) { GridVirtualizedRowElement virtualizedRоw = row as GridVirtualizedRowElement; if (virtualizedRоw != null) { elementProvider.CacheElement(virtualizedRоw); virtualizedRоw.Detach(); return; } row.Dispose(); } 
0 comments