Declan Basile
asked on
Saving a Null Value to a DataTable when a bound combobox is Cleared
In vb.net, I have a combobox's "SelectedValue" property bound to a field of a datatable. When I select an item from the combobox, the SelectedValue gets saved and the ColumnChanged event of the DataTable is triggered; however, when I clear the combobox, neither the SelectValue gets saved to the DataTable nor does the ColumnChanged event get triggered. How can I get a Null value to be saved to the bound field of the DataTable when the combobox is cleared?
ASKER
The Selected Index becomes -1 when when the selection is cleared. My problem is that it doesn't trigger an update of Null back to the bound field.
ASKER
I ended up writing the following event handler to handle the validating event ...
Dim cbx As acComboBox
cbx = CType(sender, acComboBox)
If cbx.Text = String.Empty Then
If cbx.DataBindings.Count > 0 Then
cbx.DataBindings(0).WriteValue()
End If
Exit Sub
End If
If cbx.SelectedItem Is Nothing Then
MessageBox.Show("Enter an Item from the List.")
e.Cancel = True
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Have you tried to do using following statement-
comboBox1.SelectedIndex = -1