How can I get gridcontrol records as an array?
I set an array as a datasource for a gridcontrol (devExpress component).
PersonFamily4grid[] tmpPersonFamily = new PersonFamily4grid[PersonFamiliesCOUNT];
for (int i = 0; i < PersonFamiliesCOUNT; i++)
{
tmpPersonFamily[i] = new PersonFamily4grid();
tmpPersonFamily[i].BirthDate = PersonFamilies[i].BirthDate;
tmpPersonFamily[i].Job = PersonFamilies[i].Job;
tmpPersonFamily[i].CodeMelli = PersonFamilies[i].CodeMelli;
tmpPersonFamily[i].NameFamily = PersonFamilies[i].NameFamily;
tmpPersonFamily[i].Nesbat = FamilyInfo_cbe_Nesbat.Properties.Items[PersonFamilies[i].Nesbat].ToString();
tmpPersonFamily[i].Taahol = FamilyInfo_cbe_Taahol.Properties.Items[Convert.ToInt32(PersonFamilies[i].Taahol)].ToString();
}
grid_Family.DataSource = tmpPersonFamily;
Now when the user changes data in gridcontrol, I want to get changes from the grid and affect my base array.
Why are you creating temporary array if you want to reflect changes to main array
PersonFamilies. just simply assignPersonFamiliesto gridControl’s data source and it will automatically reflect changes toPersonFamilies.If you know that class object are reference type, so their reference will not change if you assign the array directly to the gridControls data source as:
After making some changes to your data in grid view, check the object of
PersonFamiliesarray that they are updated or not. It will surely update the array of objects.If you want to work on some customized Data that contained in your
PersonFamiliesarray then you can get the Iterate your temporary arraytmpPersonFamilywithout getting it through theDataSourceproperty of GridControl and it all depends on you how you will manipulate or reflect changes to your main arrayPersonFamilies.e.g.
Hope this help..