I created a menu option to set the AutoFitStyle on my grid.
From default (AutoFitStyle.None) to AutoFitStyle.ResizeAllColumns and to AutoFitStyle.ExtendLastColumn works fine.
From AutoFitStyle.ExtendLastColumn back to AutoFitStyle.None works fine also.
But AutoFitStyle.ResizeAllColumns back to AutoFitStyle.None or AutoFitStyle.ExtendLastColumn doesn't work. It remains on AutoFitStyle.ResizeAllColumns.
I tried: this.ultraGrid.Selected.Rows.Clear();and this.ultraGrid.Refresh();before changing the AutoFitStyle but nothing seems to work.
What am I doing wrong ?
Hi Robert,
Are you sure the property is actually being set?
When you say it stays on ResizeAllColumns, does that mean that the column sizes don't immediately change? Or that even when you resize the grid, all of the columns resize?
Mike Saltzman"]Are you sure the property is actually being set?
I thinks So. I use this to set the property: this.ultraGrid.DisplayLayout.AutoFitStyle = AutoFitStyle.None;As indicated, sometimes works fine, but not after ResizeAllColumns.
Mike Saltzman"]When you say it stays on ResizeAllColumns, does that mean that the column sizes don't immediately change? Or that even when you resize the grid, all of the columns resize?
When it works the columns immediately changes. In other cases nothing happens.
When i change the columns manualy (using the right borders),then using the menu to ExtendLastColumn and/or back to None, it works fine. (immediately changes)When i use ResizeAllColumns, immediately all columns change, but they can't change back to ExtendLastColumn or None.
I hope it's a little bit clear.
Mike Saltzman"]Are you expecting that setting AutoFitStyle from ExtandLastColumn to ResizeAllColumn will see an immediate change in the grid on the screen? Because I don't think that should be the case.
That's the case. It works perfectly setting AutoFitStyle from ExtandLastColumn to ResizeAllColumn (immediate change in the grid on the screen !!!! ).Also from ExtendLastColumn to None (changes back to previous state).But nothing happens from ResizeAllColumns to ExtandLastColumn or None.
Okay, I think this is just a difference in the way the styles are implemented. For the ExtendLastColumn style, the column's width property is not changed, the grid just stretches the column's UIElements so it looks wider. For the ResizeAllColumns style, the column widths are explicitly set, so the original widths are lost.
So maybe you could store the widths of the columns or save the grid layout before setting the style. You could keep 3 different layouts in memory and when the user switches back to that style, you load the layout or set the column widths to what they were in the previous style.
Mike Saltzman"]...or save the grid layout before setting the style.
What's the best way to save the grid layout?
this.ultraGrid1.DisplayLayout.Save...
You can save the layout to a file or to a memory stream, as XML or as binary. You could also use the DisplayLayout.Clone method to simply copy the layout into another UltraGridLayout variable and store it in the grid's Layouts collection.
Thx. I'll give it a try.
Works like a charm !