wpf devexpress gridcontrol捕获集合改变事件

    xiaoxiao2025-09-14  159

    当gridcontrol的数据源itemsource改变时(添加一项或移除一项)通过下面方法可以捕获到该事件以进行相应处理

    using System.Collections.Specialized;

            private void GridControl_ItemsSourceChanged(object sender, ItemsSourceChangedEventArgs e)         {             if (e.OldItemsSource is INotifyCollectionChanged)                 ((INotifyCollectionChanged)e.OldItemsSource).CollectionChanged -= Source_CollectionChanged;             if (e.NewItemsSource is INotifyCollectionChanged)                 ((INotifyCollectionChanged)e.NewItemsSource).CollectionChanged += Source_CollectionChanged;         }

            void Source_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)         {             if (e.Action == NotifyCollectionChangedAction.Add)             {                 var tableView =gc.View as TableView;                 if (tableView != null)                 {                     // tableView.MoveLastRow();                     tableView.MoveFirstRow();                 }             }         }

    Source_CollectionChanged事件会在每次添加或删除gridcontrol数据源中的item时触发

    以上方法可以使gridcontrol默认选择第一行

    转载请注明原文地址: https://ju.6miu.com/read-1302660.html
    最新回复(0)