J
Joe
Hi all,
Tool : Excel 2003 SP2 & VBA
I am using a listboxs to show a list of items. Few of these are
priority items.
I show only those items first. Also at the bottom I added an item
"Show full list".
When the user clicks the item "Show full list", the listbox will show
all the items. If the user clicks any other item, it will show its
children items in a second list box.
I use the following code for the same. I use a function
"refresh_Listbox" to do the adding of the contents.
Level01 = First listbox
Level02 = Second Listbox
user clicks "Show full list" (here a variable named More).
refresh_Listbox(1, False) means refresh the listbox no 1 with all
items.
user clicks "Show full list" (here a variable named More).
refresh_Listbox(2, True) means refresh the listbox no 2 with only
priority items.
' ***************************
Private Sub Level01_Click()
If Level01.Value = More Then
' MsgBox Level01.ListIndex
temp = refresh_Listbox(1, False)
Level01.ListIndex = -1
Else
temp = refresh_Listbox(2, True)
End If
End Sub
' ***************************
All of these works fine except for one thing. the command
<Level01.ListIndex = -1> is not working. That means, I want to
remove the selection once it is updated. But instead what happens is
that, if the "Show full list" is the fifth item before refreshing, the
fifth item gets selected after refreshing. I dont want that to be
selected. Infact during refresing operation I clear the list and
add everything fresh. Even then it works this way.
Interestingly, if I use a msgbox command somewhere (for eg <MsgBox
Level01.ListIndex> in the code above) then it works. I mean the
Listbox will not have any selection, even if you remove the code <
Level01.ListIndex = -1>.
I have spend a day trying to figure out a way around this. Only time
it works is when I have a msgbox, which is an irritation for the user
and I dont prefer that.
I have even tried putting the code in MouseUp instead of Click. No
use.
I know this is slightly long and may be complicated. But if someone
can suggest something to understand why this is happening and a way
around, that would be great.
Thanks a lot.
Regards,
Joe
Tool : Excel 2003 SP2 & VBA
I am using a listboxs to show a list of items. Few of these are
priority items.
I show only those items first. Also at the bottom I added an item
"Show full list".
When the user clicks the item "Show full list", the listbox will show
all the items. If the user clicks any other item, it will show its
children items in a second list box.
I use the following code for the same. I use a function
"refresh_Listbox" to do the adding of the contents.
Level01 = First listbox
Level02 = Second Listbox
user clicks "Show full list" (here a variable named More).
refresh_Listbox(1, False) means refresh the listbox no 1 with all
items.
user clicks "Show full list" (here a variable named More).
refresh_Listbox(2, True) means refresh the listbox no 2 with only
priority items.
' ***************************
Private Sub Level01_Click()
If Level01.Value = More Then
' MsgBox Level01.ListIndex
temp = refresh_Listbox(1, False)
Level01.ListIndex = -1
Else
temp = refresh_Listbox(2, True)
End If
End Sub
' ***************************
All of these works fine except for one thing. the command
<Level01.ListIndex = -1> is not working. That means, I want to
remove the selection once it is updated. But instead what happens is
that, if the "Show full list" is the fifth item before refreshing, the
fifth item gets selected after refreshing. I dont want that to be
selected. Infact during refresing operation I clear the list and
add everything fresh. Even then it works this way.
Interestingly, if I use a msgbox command somewhere (for eg <MsgBox
Level01.ListIndex> in the code above) then it works. I mean the
Listbox will not have any selection, even if you remove the code <
Level01.ListIndex = -1>.
I have spend a day trying to figure out a way around this. Only time
it works is when I have a msgbox, which is an irritation for the user
and I dont prefer that.
I have even tried putting the code in MouseUp instead of Click. No
use.
I know this is slightly long and may be complicated. But if someone
can suggest something to understand why this is happening and a way
around, that would be great.
Thanks a lot.
Regards,
Joe