您的位置:首页 > 其它

wpf devexpress gridcontrol捕获集合改变事件

2016-08-15 14:38 351 查看
当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默认选择第一行
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐