【发布时间】:2015-12-03 09:02:08
【问题描述】:
我有一个 5 列的 devexpress 网格控件。第一列是一个带有一些数据的查找编辑存储库,比如说 CarTypes。
要在网格中加载数据,我使用的是BindingSource。在这个BindingSource.DataSource 我已经加载了一个IList<Cars>
然后 在我的 gridcontrol 的 dataSource 中添加了这个绑定源 像下面的
BindingSource _carsBindingSource = new BindingSource();
private void BindData(IList<Cars> data)
{
_carsBindingSource.DataSource = data;
carsGridControl.BeginUpdate();
carsGridControl.DataSource = _carsBindingSource;
carsGridControl.RefreshDataSource();
carsGridControl.EndUpdate();
}
我有一个按钮可以在我的网格“添加新车”中添加新行并在 _carBindingSource 中添加新行
private void AddNewRow()
{
_newRow = true;
_carsBindingSource.AllowNew = true;
Cars newCar = new Cars();
newCar.CarType = new CarType();
_carsBindingSource.Add(newCar );
//_carsBindingSource.Insert(0,newCar);
}
现在我想在网格的第一行添加新行。
我用Insert
_carsBindingSource.Insert(0,newCar);
但它没有用。 lookupedit repository 无法加载数据。
_carsBindingSource.Add(newCar); 可以正常工作
谁能帮帮我?谢谢!
【问题讨论】:
-
这行字是什么意思???现在你已经把你的问题写得很好,但仍然不清楚你在问什么..
-
你有权利@NiranjanKala。实际上,我想在我的 carsBindingSource 中添加一个新行,但在网格的第一行。我使用 carsBindingSource.Insert(0,newCar) 但不能正常工作
-
实际上我找到了解决方案。问题出在 GridView_CustomRowCellEdit(object sender, CustomRowCellEditEventArgs e) 事件中,我更改了 AllowEdit 值 (e.Column.OptionsColumn.AllowEdit = true;)。 .Add(object), .Insert(0,object) 一样!
标签: c# devexpress bindingsource gridcontrol devexpress-windows-ui