當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預設選擇第一行