![]() |
ListBOX1_Click problem
Hi,
This seems like it was going to be easy but I can't figure this out. I want the user to be able to select an action with a SINGLE-CLICK from listbox1, perform the action, and "reset" the selection to listindex=-1 so that the same action can be selected again if desired. I am not certain as to why but the first selected index remains selected despite the line "userform1.listbox1.listindex=-1". Please help. Thanks in advance! I have the following: Private Sub ListBox1_Click() Select Case UserForm1.ListBox1.ListIndex + 1 Case 1 Call action_1 Case 2 Call action_2 Case 3 Call action_3 End Select UserForm1.ListBox1.ListIndex = -1 End Sub Sub procedure1() action_array = Array("action #1", "action #2", "action #3") UserForm1.ListBox1.List = action_array UserForm1.Show End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub |
ListBOX1_Click problem
If your real intent is to allow selecting the item again, then don't change
the listindex property in the click event. Instead, reset the listindex property to -1 in the mousedown event. Private Sub ListBox1_MouseDown(ByVal Button _ As Integer, ByVal Shift As Integer, ByVal X As Single, _ ByVal Y As Single) ListBox1.ListIndex = -1 End Sub Private Sub ListBox1_Click() Select Case UserForm1.ListBox1.ListIndex + 1 Case 1 Call action_1 Case 2 Call action_2 Case 3 Call action_3 End Select End Sub -- Regards, Tom Ogilvy "borg" wrote in message ... Hi, This seems like it was going to be easy but I can't figure this out. I want the user to be able to select an action with a SINGLE-CLICK from listbox1, perform the action, and "reset" the selection to listindex=-1 so that the same action can be selected again if desired. I am not certain as to why but the first selected index remains selected despite the line "userform1.listbox1.listindex=-1". Please help. Thanks in advance! I have the following: Private Sub ListBox1_Click() Select Case UserForm1.ListBox1.ListIndex + 1 Case 1 Call action_1 Case 2 Call action_2 Case 3 Call action_3 End Select UserForm1.ListBox1.ListIndex = -1 End Sub Sub procedure1() action_array = Array("action #1", "action #2", "action #3") UserForm1.ListBox1.List = action_array UserForm1.Show End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub |
ListBOX1_Click problem
Thank you, Tom! You're the best!
"Tom Ogilvy" wrote: If your real intent is to allow selecting the item again, then don't change the listindex property in the click event. Instead, reset the listindex property to -1 in the mousedown event. Private Sub ListBox1_MouseDown(ByVal Button _ As Integer, ByVal Shift As Integer, ByVal X As Single, _ ByVal Y As Single) ListBox1.ListIndex = -1 End Sub Private Sub ListBox1_Click() Select Case UserForm1.ListBox1.ListIndex + 1 Case 1 Call action_1 Case 2 Call action_2 Case 3 Call action_3 End Select End Sub -- Regards, Tom Ogilvy "borg" wrote in message ... Hi, This seems like it was going to be easy but I can't figure this out. I want the user to be able to select an action with a SINGLE-CLICK from listbox1, perform the action, and "reset" the selection to listindex=-1 so that the same action can be selected again if desired. I am not certain as to why but the first selected index remains selected despite the line "userform1.listbox1.listindex=-1". Please help. Thanks in advance! I have the following: Private Sub ListBox1_Click() Select Case UserForm1.ListBox1.ListIndex + 1 Case 1 Call action_1 Case 2 Call action_2 Case 3 Call action_3 End Select UserForm1.ListBox1.ListIndex = -1 End Sub Sub procedure1() action_array = Array("action #1", "action #2", "action #3") UserForm1.ListBox1.List = action_array UserForm1.Show End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub Sub action_1() MsgBox "perform action #1" End Sub Sub action_2() MsgBox "perform action #2" End Sub Sub action_3() MsgBox "perform action #3" End Sub |
All times are GMT +1. The time now is 07:28 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com