problem with combobox

  • Thread starter Dominique Vandensteen
  • Start date
D

Dominique Vandensteen

I posted this before but did some extra testing...

combobox with 3 elements (DropDownList style)
via code (button.click) I set the selectedIndex to -1
if element at index 0 is selected then everything is fine: nothing is
selected after pressing the button
but if element at index 1 or greater is selected and i press the button,
element at index 0 is selected (uncool)

i added a selectedindexchanged listener to my combobox
i can see it passes to index -1 and directly after that it passes again to
index 0

the result is the same in framework 1.0 and 1.1
anybody an idea?





testcode:


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim r As DataRow
Dim dt As DataTable
dt = New DataTable
dt.Columns.Add("id")
dt.Columns.Add("name")
dt.Rows.Add(New Object() {1, "one"})
dt.Rows.Add(New Object() {2, "toe"})
dt.Rows.Add(New Object() {3, "tie"})

ComboBox1.DataSource = dt
ComboBox1.DisplayMember = "name"
ComboBox1.ValueMember = "id"
ComboBox1.SelectedIndex = -1
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
ComboBox1.SelectedIndex = -1
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Debug.WriteLine(String.Format("Selected index changed to [{0}]",
ComboBox1.SelectedIndex))
End Sub
 
C

Cor

Hi Dominique,

Did you test the sample I have send to you,
Because that did work on 1.1
And I was curious if it also did work on 1.0

Cor
 
H

Herfried K. Wagner [MVP]

* "Dominique Vandensteen said:
I posted this before but did some extra testing...

combobox with 3 elements (DropDownList style)
via code (button.click) I set the selectedIndex to -1
if element at index 0 is selected then everything is fine: nothing is
selected after pressing the button
but if element at index 1 or greater is selected and i press the button,
element at index 0 is selected (uncool)

Maybe setting it to -1 twice will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top