I bound my grid to a DataSet that has a unique ID column that I set to display read-only. In order to add a new row, I added a custom command and am trying the code below. When I try to add a row, the first one gets added and it displays with the next ID on the screen, e.g. I have -1, 1, 2, 3. The new row shows up with a "4". But then when I try to add another row, I get a unique constraint error because the "4" was not put into the datasource but was only being displayed. When I check the Row behind the data, I see that the user's keyed in value on the grid appears in the row but the value I populated programmatically does not like this:
The 0th element was populated with a "4" so not sure where it went! I tried a whole bunch of different things like calling "AcceptChanges" on the Row in the DataSource but nothing seems to work in trying to get the ID column value to go to the datasource.
Help will be very much appreciated.
if (GridWeb1.ActiveSheetIndex == 0)
int maxval = 1;
for (int i = 1; i <= GridWeb1.WebWorksheets.ActiveSheet.CurrentBindRows; i++)
if ((int.Parse((string)GridWeb1.WebWorksheets.ActiveSheet.Cells[i, 0].Value)) > maxval)
maxval = (int.Parse((string)GridWeb1.WebWorksheets.ActiveSheet.Cells[i, 0].Value));
int row = GridWeb1.WebWorksheets.ActiveSheet.CreateNewBindRow();
GridWeb1.WebWorksheets.ActiveSheet.Cells[row, 0].PutValue(((int)(maxval + 1)).ToString());
// Scrolls the panel to the bottom.
GridWeb1.ViewPanelScrollTop = int.MaxValue.ToString();