I'd seriously recommend another approach....First, pull over two queries
with two dataadapters. If the tables are in a Parent Child format, (where
the top combobox uses the parents data and the child data is displayed in
the bottom one, you may want to use a DataRelation). Or, if they aren't,
you can just bind the bottom one to a dataview and set it's rowfilter to
correspond to whatever was selected in the top combobox.
DataReaders rock and they are very easy to use..but you'll potentially be
making a LOT of trips to the DB that aren't necessary if you do it that way.
However, more to the point, what happens if you set the selectedIndex of the
combobox to -1? That should do it for you although I just used similar code
and can't cause the problem to happen.
If you want to pursue the DataBound method, this should help, and either
way, the -1 index should do it for you.
Here's some code I use to do essentailly the same thing with a grid. I bind
the grid to a dataview..Then when the comboboxes selectedindex changes, I
reset the rowfilter:
Dim dv2 As New DataView(ds.Tables(0))
dv2.RowFilter = "Work_Type = '" CType(cboDepartment.SelectedItem, String)"'"
Newbee said:
I am filling the combobox like so:
Try
GioCn.Open()
Dim reader3 As SqlDataReader
reader3 = cmd.ExecuteReader()
While reader3.Read
ComboBox1.Items.Add(reader3.GetSqlString(0))
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
GioCn.Close()
End Try
The above coding is fired when the combobox0 (the combobox above it) value
is changed. (valuechanged). i.e when combobox0 value is changed, this code
is run to fill comboBox1.