0

I create a datatable in code and set it to a gridcontrol (DevExpress component) to show it like the code here (add one row to datatable and set it as datasource of 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;

The user can change data in my gridcontrol. I want to have changes in my gridcontrol updated to my datatable. How can I do that (row edited, row deleted)?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hamze
  • 7,061
  • 6
  • 34
  • 43

1 Answers1

0

I found the solution: in Family_gridView_CellValueChanged event, add this code:

PersonFamiliesDataTable = (DataTable)grid_Family.DataSource;

So after any changes happen to cells of grid, my datatable is being updated. Be careful, this event comes up when the user change a cell and focus leave it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
hamze
  • 7,061
  • 6
  • 34
  • 43