ComboBox first entry text is displayed,but SelectedIndex = -1

  • Thread starter Thread starter Scott M
  • Start date Start date
S

Scott M

I have combo boxes that use DataTables as the data source and while they
load just fine but the problem is that the text for the first entry in the
list is always displayed in every combo box (when it should be blank), even
though I set the SelectedIndex to -1. I cannot seem to find any way to stop
this. Any ideas?

Private Sub SetCustomersCombo()
m_Processing = True
' Sets the Data Table object associated with this Combo Box
With Me.cboSelectCustomer
.BeginUpdate()
.DataSource = m_DTCustomers
.DisplayMember = "Display"
.ValueMember = "ID"
.EndUpdate()
.SelectedIndex = -1
End With
m_Processing = False
End Sub

...snippet of code that loads the DataTable object

ItemIndex = 0
With m_DTCustomers
.Clear()
.Columns.Add(New DataColumn("ID", GetType(Integer)))
.Columns.Add(New DataColumn("Display", GetType(String)))
Do While MyDataReader.Read
.Rows.Add(.NewRow())
.Rows(ItemIndex)(0) = MyDataReader.GetInt32(0)
.Rows(ItemIndex)(1) = MyDataReader.GetString(1)
ItemIndex += 1
Loop
End With
 
Hello,

Scott M said:
I have combo boxes that use DataTables as the data
source and while they load just fine but the problem is that the
text for the first entry in the list is always displayed in every
combo box (when it should be blank), even though I
set the SelectedIndex to -1. I cannot seem to find any
way to stop this. Any ideas?

BUG: ComboBox Does Not Clear When You Set SelectedIndex to -1
http://support.microsoft.com/?id=327244

HTH,
Herfried K. Wagner
 
Back
Top