combobox bug???

  • Thread starter Dominique Vandensteen
  • Start date
D

Dominique Vandensteen

dotnet framework v1.0.3705 in vs 2002
code below
whats happening

when I select something else than first element in my combobox and then I do
a combobox1.selectindex = -1 the first element is selected
so instead of being -1 it is 0 (checked with debugger)
if the first element is checked and I do combobox1.selectindex = -1, then
nothing is selected (normal)
the thing is that I have to call ComboBox1.SelectedIndex = -1 twice
but also the indexchanged event is raised twice (unkewl)

somebody saw this problem?




code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim table As DataTable
table = New DataTable()
table.Columns.Add("id")
table.Columns.Add("name")
table.Rows.Add(New Object() {1, "one"})
table.Rows.Add(New Object() {2, "two"})
table.Rows.Add(New Object() {3, "much more"})
ComboBox1.DataSource = table
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
 
K

Ken Tucker [MVP]

Hi,

The only way I found to do it is in a thread.


With ComboBox1

.DataSource = ds.Tables(0)

.DisplayMember = "Name"

.ValueMember = "id"

End With

Dim trdChange As New System.Threading.Thread(AddressOf ChangeComboIndex)

trdChange.Start()



Private Sub ChangeComboIndex()

ComboBox1.SelectedIndex = -1

End Sub



Ken
 
C

Cor

Hi Dominique,

I did not see that code of you made it new.

When I try this the behaviour it is as I would expect.

This is with 2003 so when not, we can try it again.

I hope this helps you

Cor

Dim bool As Boolean
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim dt As New DataTable
Dim dc1 As New DataColumn("A")
dt.Columns.Add(dc1)
Dim adt() As String = {"Belgie", "Nederland", "Luxemburg"}
For i As Integer = 0 To adt.Length - 1
Dim dr As DataRow = dt.NewRow
dr(0) = adt(i)
dt.Rows.Add(dr)
Next
Me.ComboBox1.BeginUpdate()
Me.ComboBox1.DisplayMember = "A"
Me.ComboBox1.ValueMember = "A"
Me.ComboBox1.DataSource = dt
Me.ComboBox1.EndUpdate()
Me.ComboBox1.SelectedIndex = -1
bool = True
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If bool Then
MessageBox.Show(Me.ComboBox1.Text & "|" & _
Me.ComboBox1.SelectedIndex.ToString)
Me.ComboBox1.SelectedIndex = -1
End If
End Sub
///
 

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