|
-
Apr 5th, 2009, 11:04 AM
#1
Thread Starter
PowerPoster
[RESOLVED] listbox - selectionmode = none issues
Hello,
I would like to have a listbox where I can pre-select an item in code, but prevent the user from selecting a different item (i.e. a "read-only" listbox). I don't want to disable the listbox, because then the user can't scroll it. If I set selectionmode = none, then I can't select an item in code. Any ideas on how I can achieve the results I am looking for here?
Thanks,
Bruce
Last edited by BruceG; Apr 5th, 2009 at 01:21 PM.
Reason: resolved
"It's cold gin time again ..."
Check out my website here.
-
Apr 5th, 2009, 11:26 AM
#2
Re: listbox - selectionmode = none issues
try this. pre-select your item , then set selectionmode in code
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 5th, 2009, 11:41 AM
#3
Thread Starter
PowerPoster
Re: listbox - selectionmode = none issues
Thanks, .paul., but unfortunately that does not work. What happens is, when I set selectionmode = none in code, the item that I previously selected in code is de-selected.
"It's cold gin time again ..."
Check out my website here.
-
Apr 5th, 2009, 11:52 AM
#4
Re: listbox - selectionmode = none issues
ok. this works. its an extended listbox that can only have its selectedindex changed in code:
vb Code:
Public Class listboxEx
Inherits ListBox
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Private Const WM_KEYDOWN As Integer = &H100
Private Const WM_KEYUP As Integer = &H101
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_LBUTTONDOWN OrElse m.Msg = WM_LBUTTONUP OrElse m.Msg = WM_KEYDOWN OrElse m.Msg = WM_KEYUP Then Return
MyBase.WndProc(m)
End Sub
End Class
Last edited by .paul.; Apr 5th, 2009 at 12:10 PM.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 5th, 2009, 12:05 PM
#5
Re: listbox - selectionmode = none issues
You could just add a selection code on the index changed event
Code:
ListBox1.SelectedIndex = 1
So every time they change it, it instantly changes back.
-
Apr 5th, 2009, 01:20 PM
#6
Thread Starter
PowerPoster
Re: listbox - selectionmode = none issues
.paul.,
Very nice, I must say. I tried it out and it works great. I see you added it to your bag of tricks in your signature, as well you should. I think this little gem fills a need. Thanks very much!
Vectris - thanks for your input. I did the kind of thing you are talking about in VB6, but was hoping for a more elegant solution in .NET. As we can see, .NET still does not offer the desired functionality "out of the box", but .paul.'s extension gets the job done nicely.
"It's cold gin time again ..."
Check out my website here.
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
|