|
-
Mar 28th, 2007, 01:11 PM
#1
Thread Starter
Frenzied Member
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.
-
Mar 28th, 2007, 01:25 PM
#2
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
-
Mar 28th, 2007, 01:37 PM
#3
Thread Starter
Frenzied Member
Re: ListBox - Highlight 1st Item
 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 
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?
-
Mar 28th, 2007, 01:40 PM
#4
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.)
-
Mar 28th, 2007, 01:47 PM
#5
Re: ListBox - Highlight 1st Item
 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.
-
Mar 28th, 2007, 01:48 PM
#6
Thread Starter
Frenzied Member
Re: ListBox - Highlight 1st Item
 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
 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 ) 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.
 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
I know this, just from this site
-
Mar 28th, 2007, 01:53 PM
#7
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?"
-
Mar 28th, 2007, 01:57 PM
#8
Thread Starter
Frenzied Member
Re: ListBox - Highlight 1st Item
 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.
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.
-
Mar 28th, 2007, 01:59 PM
#9
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.
-
Mar 28th, 2007, 02:11 PM
#10
Thread Starter
Frenzied Member
Re: ListBox - Highlight 1st Item
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|