XtraGrid的一些资料

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值