listbox selected index changes problem

mark103

Member
Joined
Apr 13, 2008
Messages
11
Programming Experience
3-5
Hi guys

I have problem with listbox. When I selected the item "Item1" from combobox1, then press button1 to clear and add the items on list1. Then make the first item on list1 to get selected. So after that I selected the second item on selected index on my list1 then selected the item "Item2" from combobox2 and press button1 without clear or add any items, it suppose to be selected the second item on list1 to get selected but when I press the button1, it return to the first item on list1.


Here it the code:

VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If Me.ComboBox1.SelectedItem = "Item1" Then
            List1.Items.Clear()
            List1.Items.Add(My.Resources.RuntimeStrings_test.1)
            List1.Items.Add(My.Resources.RuntimeStrings_test.2)
            ListBox1.SelectedIndex = 0
        End If


        If Me.ComboBox2.SelectedItem = "Item2" Then 
            ListBox1.SelectedIndex = 1
        End If
        Me.Button1.Enabled = False
    End Sub




How I can stop the loops returning to selected index one whens when I selected "item2" from combobox2 and click the button1??



Thanks,
Mark
 
Back
Top