ListBox - Highlight 1st Item
When I load a listbox I am trying to have the first item highlighted, but each time I do I seem to fire the click event some how.
I have the following:
vb Code:
lstSearch.Selected (0) = true
but this acts as if it has been clicked.
I am just after getting it highlighted, but nothing else.
Re: ListBox - Highlight 1st Item
set a boolean flag:
Code:
Private bNoClick As Boolean
Private Sub Form_Load()
bNoClick = True
lstSearch.Selected(0) = True
bNoClick = False
End Sub
Private Sub lstSearch_Click()
If bNoClick Then Exit Sub
' Code
End Sub
Re: ListBox - Highlight 1st Item
Quote:
Originally Posted by bushmobile
set a boolean flag:
Code:
Private bNoClick As Boolean
Private Sub Form_Load()
bNoClick = True
lstSearch.Selected(0) = True
bNoClick = False
End Sub
Private Sub lstSearch_Click()
If bNoClick Then Exit Sub
' Code
End Sub
Thanks bushmobile :D
So decaring this in the form load would work only when the form was first loaded - yes?
So, if the user does a second search, without closing and re-opening the form, would this work?
Re: ListBox - Highlight 1st Item
No...it will only work in the form load.
What do you have in the click event that you don't want run?
(Incidentially, bushmobile's method is what I've always used.....I laid back on this one to see if anyone else had a better solution.)
Re: ListBox - Highlight 1st Item
Quote:
Originally Posted by aikidokid
So decaring this in the form load would work only when the form was first loaded - yes?
So, if the user does a second search, without closing and re-opening the form, would this work?
basically if you're changing which List item has focus and you don't want it to fire the _Click event then you set the boolean to True in the line before (you then set it to false the line after, so _Click events can fire again).
I don't really understand what you're trying to say, but it's not a one off thing - you have manually decide when it ignores the _Click and when it doesn't.
Re: ListBox - Highlight 1st Item
Quote:
Originally Posted by Hack
No...it will only work in the form load.
That's what I thought, but I just wanted to make sure - been a long day so far ;)
Quote:
Originally Posted by Hack
What do you have in the click event that you don't want run?
What I would like to do is, when the listbox is first loaded, is have the first item highlighted. then if the user (me :lol:) wants to navigate with the keyboard, it would highlight each selection to show where they were.
It's not crucial, but I just liked the idea for clarity.
In the Click event I have the code that loads the selected file from the DB to the RTB on the main form.
Quote:
Originally Posted by Hack
(Incidentially, bushmobile's method is what I've always used.....I laid back on this one to see if anyone else had a better solution.)
Always worth looking about :p
I know this, just from this site :thumb:
Re: ListBox - Highlight 1st Item
One thing about using "workarounds" is that you should document what you are doing and why. Not for anyone else looking at your code, but so that you, 6 months from now, won't scratch your head and ask yourself "what the heck did I do that for?"
Re: ListBox - Highlight 1st Item
Quote:
Originally Posted by Hack
One thing about using "workarounds" is that you should document what you are doing and why. Not for anyone else looking at your code, but so that you, 6 months from now, won't scratch your head and ask yourself "what the heck did I do that for?"
thanks for the advice.
One thing that I am getting better at is copious amounts of commenting.
I don't have to wait 6 months to wonder what I was doing. :lol:
I though this would be some property setting that I had missed, but obviously it's not that straight forward.
Like bushmobile says, sort out when you want to fire the click event and do it manually.
Re: ListBox - Highlight 1st Item
The more experienced you get, the more you will find your code documentation diminish. But, these little "juryrigs" need to always be commented.
And, you have discovered what will continue to be an "feature" of the listbox. :sick:
Re: ListBox - Highlight 1st Item
Quote:
Originally Posted by Hack
And, you have discovered what will continue to be an "feature" of the listbox.
Ah well, something else to take a look at, along with writing th rest of the app. :wave: