Free Support Forum - aspose.com

Grid not saving the column value for a Databound grid with a unique read-only ID column

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:

? ((DataRowView)GridWeb1.WebWorksheets.ActiveSheet.GetRowBindObject(5)).Row.ItemArray
{Dimensions:[2]}
[0]: {}
[1]: "dfvdfv"

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.

T.

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());
GridWeb1.WebWorksheets.ActiveSheet.CommitNewBindRow();
// Scrolls the panel to the bottom.
GridWeb1.ViewPanelScrollTop = int.MaxValue.ToString();
}

I have figured out that if I try to set the cell's value using code-behind as above (PutValue), the datasource value is not changed. If I make that ID column editable and the user types in a value, then the value is applied to the datasource. Is this a bug or am I using it the wrong way?

Thanks,

T.

Hi,

Thank you for trying our product.

In data-binding mode, if you want to modify a cell's value by coding, you also need to update its datasource manually. This is not a bug. We designed the control in this way because we think that it would provide more flexibility.

The WebWorksheet object has a event called "InitializeNewBindRow". When you add a new bind row to the grid, you may handle this event to initialize the new DataRow.

I have a similar problem, did you ever get a response on this issue?

Never mind, I found the full thread.

Still functionality is strange, the grid seems well bound to the dataset, except when adding a new row???