我在代码中创建datatable
并将其设置为gridcontrol
(DevExpress component
),以便像此处的代码一样显示(向datatable
添加一行并设置它作为datasource
)的gridcontrol
:
DataTable PersonFamiliesDataTable = new DataTable();
PersonFamiliesDataTable.Columns.Add("BirthDate", typeof(String));
PersonFamiliesDataTable.Columns.Add("Job", typeof(String));
PersonFamiliesDataTable.Columns.Add("NameFamily", typeof(String));
DataRow PersonFamilyRow = PersonFamiliesDataTable.NewRow();
PersonFamilyRow["BirthDate"] = DateTimePicker_FamilyInfo_BirthDate.Text;
PersonFamilyRow["Job"] = FamilyInfo_txt_job.Text;
PersonFamilyRow["NameFamily"] = FamilyInfo_txt_NameFamily.Text;
PersonFamiliesDataTable.Rows.Add(PersonFamilyRow);
grid_Family.DataSource = PersonFamiliesDataTable;
用户可以更改gridcontrol
中的数据。我希望将gridcontrol
的更改更新为datatable
。我该怎么做(行编辑,行删除)?
答案 0 :(得分:0)
我找到了解决方案:在Family_gridView_CellValueChanged
事件中,添加以下代码:
PersonFamiliesDataTable = (DataTable)grid_Family.DataSource;
因此,在网格单元格发生任何更改后,我的datatable
正在更新。请注意,当用户更改单元格并将焦点保留时,会出现此事件。