开发者

DevExpress WPF Grid - Event when columns width is changed

does anyone knows, which event is raised, when user changes开发者_C百科 width of column for WPF DevExpress grid? I want to use it to store columns widths in database.


You Can store columns widths by event View.LostFocus:

DevExpress.Xpf.Grid.GridControl grc = new DevExpress.Xpf.Grid.GridControl(); grc.View.LostFocus += View_LostFocus;

And with handler:

 void View_LostFocus(object sender, RoutedEventArgs e)
  {
        TableView tv = sender as TableView;
        GridColumn[] gcs = tv.VisibleColumns.ToArray();
        foreach (GridColumn gc in gcs)
        {
            if (gc.ActualHeaderWidth != gc.Width)
            {
                double newWidth = gc.ActualHeaderWidth; //Do something with new width
            }
        }
    }


I've had to do the same, but for the silverlight grid. The best i could get was to handle the Grid.LayoutUpdated event, and enumerate the columns to get their widths. I couldn't even bind to the column width property in the silverlight grid because it wasn't a dependency property, the WPF grid is most likely exactly the same.

EDIT: what you could do though is check through the source code of the WPF grid, and add a ColumnResized event yourself. It's not ideal, because you would have to re-integrate the code everytime you installed a DevExpress update, and then rebuild the grid. You would also need to be careful how you do it, for instance you need to work out the best way to determine when a column resize has finished, so that you don't continually fire the event. Or you could look round for a more fully featured (more mature) grid?


The DataGridColumnHeader exposes a SizeChanged event which passes the SizeChangedEventArgs object to you in which a lot of useful Sizes info is exposed!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜