Display Artifacts after Rebinding Telerik RadGridView
I had a display issue where the column widths changed after rebinding data with the RadGridView. Clicking the columns restored the proper widths.
I initially went with the Telerik recommendation to use CellFormatting to set column fonts, colors, widths, etc. Since their were problems I needed to come up with a solution.
Telerik recommendation:
private void Form1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) { //Set the font and size of the Sizes column if (e.Column.FieldName == "GarmentSizeID" || e.Column.FieldName == "GroupSizeOrder") { e.Column.IsVisible = false; e.Column.ReadOnly = true; } if (e.Column.FieldName == "ShortName") { e.Column.MinWidth = 75; e.Column.Width = 75; } }
What worked for me when I rebinded.
private void Form1_Load(object sender, EventArgs e) { //PopulateGrid() AdjustRadGridViewColumns(); } public void AdjustRadGridViewColumns() { //Ensure the base values aren't null if (radGridView1==null || radGridView1.Columns == null)return; //Adjust column widths and visibility foreach (var c in radGridView1.Columns) { switch (c.Name) { case "GarmentSizeID": case "GroupSizeOrder": c.IsVisible = false; c.ReadOnly = true; break; case "ShortName": c.MinWidth = 75; c.Width = 75; break; } } }
Leave a Reply