Hello.
I have a VB.Net application with two forms. The first form consists of a grid that is bound to a datasource. If the user double-clicks a row in the grid, the second form then displays the values of the selected row in bound textboxes which allow for updating or deleting the record. This is accomplished by passing a bindingsource to the detail form via a .showdialog() call and binding all the textboxes to the passed in bindingsource. This functionality is working with no problems.
The problem I'm having is with adding new records to the underlying datatable using the same detail form. The first form has an "Add New Record" button that also calls the detail form.
Specifically, the problem is that when I call bindingSource.AddNew on the detail form, I get an error because non-string fields are not allowing a new row to be created if they contain null values (which seems to be the default when .AddNew is called). I've been able to work around this by inserting (using a dataRowView) 0's for integer fields and some arbitrary date for date fields but it seems like there must be a better way to do this. I don't like this approach because these temporary values are then displayed in the various textboxes. All of this processing is being done before the form is displayed and before the user enters any values to be inserted.
It would be very helpful if you could post a simple example of passing a bindingsource into a form that can both add and edit records.
Thanks very much for any assistance you can provide.
I have a VB.Net application with two forms. The first form consists of a grid that is bound to a datasource. If the user double-clicks a row in the grid, the second form then displays the values of the selected row in bound textboxes which allow for updating or deleting the record. This is accomplished by passing a bindingsource to the detail form via a .showdialog() call and binding all the textboxes to the passed in bindingsource. This functionality is working with no problems.
The problem I'm having is with adding new records to the underlying datatable using the same detail form. The first form has an "Add New Record" button that also calls the detail form.
Specifically, the problem is that when I call bindingSource.AddNew on the detail form, I get an error because non-string fields are not allowing a new row to be created if they contain null values (which seems to be the default when .AddNew is called). I've been able to work around this by inserting (using a dataRowView) 0's for integer fields and some arbitrary date for date fields but it seems like there must be a better way to do this. I don't like this approach because these temporary values are then displayed in the various textboxes. All of this processing is being done before the form is displayed and before the user enters any values to be inserted.
It would be very helpful if you could post a simple example of passing a bindingsource into a form that can both add and edit records.
Thanks very much for any assistance you can provide.