We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I force the new row start editing when unbound cell is changed

Hi, I have a databoundGrid (1.6.1.8) with an unbound column. I have buttons in this column. When the button is clicked I am setting some values in the bound columns of the same row. It works fine if I start editing the new row in a bound column. But if I click the button (unbound column) my code (grid[curRow, someCol].CellValue = "xyz") is failing. How do I let the binder know that "Go ahead and add a new row". You can see the same effect in the GridMultiHeader sample. 1. Run the sample. 2. Highlite "WILMK" and "WOLZA" rows and hit delete key. 3. Without clicking on any other cells, click on the drop down calendar in the unbound cell and pick a date. You will see the date now. 4. Click on the checkbox above the drop down. 5. The date disappears from the last row. 6. But if you type abc in the last row customer id and then select a date, it seems to work. Any ideas on how to add this new row before editing the bound column? thanks, - Reddy

1 Reply

AD Administrator Syncfusion Team February 28, 2004 06:56 AM UTC

In the sample, the unbound column values are stored in a hashtable using CustomerID as the lookup key. So, when you enter the unbound value in the AddNew row without adding a CUstomerID value, there is no key for the hashtable, so the value does not get saved. I think you can use CurrentCellStartEditing to add a new row directly to the DataTable. Normally, if you have a primary key column, calling DataTable.NewRow would populate the primary key for you. But the NorthWind database does not auto populate customerID, so you would either do it yourself, or not let the user leave the row (RowLeave event) until he provided the value. Here is code that worked for me in the sample. It populates the customerID column. One other thing for this NorthWind Database is the CustomerName has a non-empty constraint on it. So, to avoid this constraint exception, the code puts a blank into that field as well.
private int id = 0;
private void gridDataBoundGrid1_CurrentCellStartEditing(object sender, CancelEventArgs e)
{
	GridDataBoundGrid grid = (GridDataBoundGrid) sender;
	GridCurrentCell cc = grid.CurrentCell;
	if(cc.RowIndex == grid.Model.RowCount && grid[0, cc.ColIndex].Text == "Unbound")
	{
		DataRow dr = this.dataSet11.Customers.NewRow();
		dr[dataSet11.Customers.CustomerIDColumn.ColumnName] = string.Format("custID{0}", id++); 
		dr[dataSet11.Customers.CompanyNameColumn.ColumnName] = ""; 
		dataSet11.Customers.Rows.Add(dr);
	}
}

Loader.
Up arrow icon