i have a listbox with items. when i select an item(the second for example), the listbox items get resorted and the first item should then be selected. what happens is that the second item stays selected.
what i have so far:
form:
listbox(listbox1)
button(Commandbutton1)
button(Commandbutton2)
button(Commandbutton3)
the code:
Option Explicit
Private boo As Boolean
Private Sub UserForm_Initialize()
f1
boo = True
End Sub
Private Sub CommandButton1_Click()
f1
End Sub
Private Sub CommandButton2_Click()
f2
boo = False
Me.ListBox1.Selected(0) = True ' this fires ListBox1_Click. Boo ensures that ListBox1_Click's code is not executed
boo = True
End Sub
Private Sub CommandButton3_Click()
MsgBox Me.ListBox1
End Sub
Private Sub ListBox1_Click()
If boo Then
Debug.Print Me.ListBox1, "click"
CommandButton2_Click
End If
End Sub
Sub f1()
With Me.ListBox1
.Clear
.AddItem "AAP"
.AddItem "NOOT"
.AddItem "MIES"
End With
End Sub
Sub f2()
With Me.ListBox1
.Clear
.AddItem "NOOT"
.AddItem "MIES"
.AddItem "AAP"
End With
End Sub
When i click button2 everything works as expected(the first item gets selected) and button 3 shows the correct value(item1)
When i select the second item in the listbox, the second item stays selected. Expected behaviour should be 1st gets selected. button3 throws error(there is a null) (i could show debug.print listbox1.columns(0,0) but that is not the point.
thanks in advance,
pancras
what i have so far:
form:
listbox(listbox1)
button(Commandbutton1)
button(Commandbutton2)
button(Commandbutton3)
the code:
Option Explicit
Private boo As Boolean
Private Sub UserForm_Initialize()
f1
boo = True
End Sub
Private Sub CommandButton1_Click()
f1
End Sub
Private Sub CommandButton2_Click()
f2
boo = False
Me.ListBox1.Selected(0) = True ' this fires ListBox1_Click. Boo ensures that ListBox1_Click's code is not executed
boo = True
End Sub
Private Sub CommandButton3_Click()
MsgBox Me.ListBox1
End Sub
Private Sub ListBox1_Click()
If boo Then
Debug.Print Me.ListBox1, "click"
CommandButton2_Click
End If
End Sub
Sub f1()
With Me.ListBox1
.Clear
.AddItem "AAP"
.AddItem "NOOT"
.AddItem "MIES"
End With
End Sub
Sub f2()
With Me.ListBox1
.Clear
.AddItem "NOOT"
.AddItem "MIES"
.AddItem "AAP"
End With
End Sub
When i click button2 everything works as expected(the first item gets selected) and button 3 shows the correct value(item1)
When i select the second item in the listbox, the second item stays selected. Expected behaviour should be 1st gets selected. button3 throws error(there is a null) (i could show debug.print listbox1.columns(0,0) but that is not the point.
thanks in advance,
pancras