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默认选择第一行
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默认选择第一行
相关文章推荐
- Devexpress 之gridControl双击行事件
- devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)
- Dev gridcontrol 捕获按键事件
- WPF DevExpress GridControl 什锦(陆续更新中~~~)
- [ WPF ] DevExpress.Xps.grid.GridControl怎么可以让所有内容居中显示
- WPF Devexpress GridControl Value与Display转换
- devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)
- WPF DevExpress GridControl TableView 全选 和反选 以及获取选中行的数据
- DevExpress.XtraGrid.GridControl GridView 根据条件动态改变 RepositoryItemButtonEdit 的Caption
- DevExpress控件-GridControl根据条件改变单元格/行颜色(Dev GridControl 单元格着色) z
- [DevExpress]GridControl根据条件改变单元格/行颜色(Dev GridControl 单元格着色)
- WinForm编程入门--DEVEXPRESS GridControl button点击事件
- devexpress GridControl wpf控件使用
- devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)
- devexpress表格控件gridcontrol设置隔行变色、焦点行颜色、设置(改变)显示值、固定列不移动(附源码)
- Dev gridcontrol 捕获按键事件
- DevExpress控件-GridControl根据条件改变单元格/行颜色(Dev GridControl 单元格着色)
- wpf devexpress gridcontrol分组统计功能
- WPF-DevExpress/WPF/GridControl用XML文件作为数据源总结
- 在.net cf(C#)中捕获输入法面板(InputPanel&SIP)高度改变事件