Combobox error

MSGill

New member
Joined
Dec 18, 2005
Messages
1
Programming Experience
1-3
I have a master-detail form on which I have a datagridview(detail) that is bound to a table. Within that grid one of the columns displays values from another table using a combobox. Under normal circumstances this all works quite well. However, if you go to the new record at the bottom of the grid and click the down arrow of the combobox the autonumber field populates as it should and the master key value is also automatically entered as it should be. The problem is that if the user decides not to select a value from the list and they try to delete the line they get an error message (Current item cannot be removed from the list because there is no current item.).

I tried to disable the delete button of the bindingnavigator when the form starts if the bindingsource count is not > 0 which works, but as soon as the user begins to edit the new record of the grid it is enabled again.

I have also tried taking the on_click event of the navigator delete button, but it resumes afterwards.

I may have to create a record if the user does not do so and the let the bindingnavigator delelte that record. It just seems like a sloppy way of doing things.

I would appreciate any other suggestions.

Thanks,
Michael
 

DavidT_macktool

Well-known member
Joined
Oct 21, 2004
Messages
502
Location
Indiana
Programming Experience
3-5
Set the value on Add

What if you set the default value for the combobox field when you add a record.

VB.NET:
    Private Sub DetailGrid_Add(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DetailGrid.OnAddNew
      'Set the default value here.
    End Sub
Not sure how it works in a grid but you set the index to a combobox like this.
ComboBox1.SelectedIndex = 1

Hope this gives you some other ideas...
 
Top Bottom