2012-06-14 76 views
0

我創建一個datatable的代碼並將其設置爲gridcontrolDevExpress component)以顯示它像這裏的代碼(添加一行到datatable並將其設置爲的gridcontroldatasource):如何更改gridview更新爲datatable,我創建代碼

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

我找到了解決辦法:在Family_gridView_CellValueChanged事件,添加以下代碼:

PersonFamiliesDataTable = (DataTable)grid_Family.DataSource; 

所以經過任何改變發生電網的細胞,我datatable正在更新。要小心,當用戶改變一個單元並且重點離開它時,這個事件就會出現。