Bindingsource C# Adding New Event
-
Hi, We are using data-binding & typed datasets in our C# .NET 2.0 application (VS2005). We have a bindingsource which has as datasource a dataset and as datamember a datatable. In the form we have a grid which is binded to that bindingsource. We allow new records to be created on the grid. When the users navigates to a new row, the "Adding New" event is raised. We would like to handle this event because we need to set the key of the record to a new Guid. We get as parameter of the "Adding New" function "AddingNewEventArgs e". Then e.NewObject should be set. Well, this doesn't work. After setting the e.NewObject the program crashes. It's like it does not accept my Typed DataRow. Maybe the collection underneath in the Bindingsource accepts another type? Any ideas? Best regards, Jens
-
Hi, We are using data-binding & typed datasets in our C# .NET 2.0 application (VS2005). We have a bindingsource which has as datasource a dataset and as datamember a datatable. In the form we have a grid which is binded to that bindingsource. We allow new records to be created on the grid. When the users navigates to a new row, the "Adding New" event is raised. We would like to handle this event because we need to set the key of the record to a new Guid. We get as parameter of the "Adding New" function "AddingNewEventArgs e". Then e.NewObject should be set. Well, this doesn't work. After setting the e.NewObject the program crashes. It's like it does not accept my Typed DataRow. Maybe the collection underneath in the Bindingsource accepts another type? Any ideas? Best regards, Jens
JensB wrote:
we need to set the key of the record to a new Guid.
I did that in several data-bound DataGridViews with no problems. You don't set the e.NewObject to something. Here is how I did it.
private void MyDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
MyDataGridView.Rows[e.RowIndex].Cells[0].Value = Guid.NewGuid().ToString();
}Regards:rose: