`
signingoff
  • 浏览: 81106 次
  • 性别: Icon_minigender_1
  • 来自: 福建
社区版块
存档分类
最新评论

XtraGrid的一些资料

ORM 
阅读更多
Basically yes, but not completely.

In general there are two ways to add new rows to the grid:

#1 Add new rows to the datasource

If the datasource supports the IBindinglist interface, as System.Data.DataTable or System.ComponentModel.BindingList does, the the grid will automatically updated, otherwise the GridView.LayoutChanged method has to be called to update the grid.

#2 Add new rows to the grid

This can be done by calling the GridView.AddNewRow. But in only works for datasources that supports the IBindingList interface, this is because the IBindingList.AddNew method is called in this case.


Please have a look into sample project I created for you.


DevExpress XtraGrid控件功能非常强大,支持的数据源类型也特别多,在采用ORM方案的项目中,我们很多时候都没有通过 DataTable来作为界面层的数据源,而是采用对象数组或实现了IEnumerable接口的数据对象,例如:ArrayList、 ILIST<T>等。这些类型简单方便,也是很多开源系统中常见的实现方式。XtraGrid控件对这类数据源也提供了支持,查询、修改和删除都可以,唯一不能实现的就是增加记录并刷新表格。

但是我们不想因为增加一条记录,还要重新刷新整个数据源,那该怎么办?
DevExpress公司给出了一种实现方式:
程序代码 程序代码

ArrayList data = new ArrayList();
gridControl1.DataSource = data;
...
data.Add(myObject);
gridControl1.MainView.LayoutChanged();

当然,也提到了为数据对象实现IBindingList,但是这些方式我觉得并不是很方便。
我认为最理想的方式就是利用BindingList<T>来进行包装,因为这样就可以象DataTable一样了,感觉比较统一,也不用改变数据对象:
程序代码 程序代码

IList<SystemAccount> list = new List<SystemAccount>();
...
BindingList<SystemAccount> bindingList = new BindingList<SystemAccount>(list);
list.AddingNew += new AddingNewEventHandler(AccountList_AddingNew);

gridControl1.DataSource = bindingList;
//////////
AddNewRow在dataView.rowFilter以后会失去效果



private void gridView1_ShownEditor(object sender, System.EventArgs e) {
   if(gridView1.FocusedRowHandle ==
DevExpress.XtraGrid.GridControl.NewItemRowHandle && gridView1.ActiveEditor
!= null)
      gridView1.ActiveEditor.IsModified = true;
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics