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.
Unfortunately, activation email could not send to your email. Please try again.

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

Thread ID:





11240 Feb 27,2004 04:05 PM Feb 28,2004 01:56 AM Windows Forms 1
Tags: GridControl
Administrator [Syncfusion]
Asked On February 27, 2004 04:05 PM

Hi, I have a databoundGrid ( 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

Administrator [Syncfusion]
Replied On February 28, 2004 01:56 AM

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] = ""; 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.