|
-
Jun 25th, 2004, 12:34 PM
#1
Thread Starter
Frenzied Member
Listbox Select Multiple
I need a way for my user to be able to select multiple items in a listbox, and still be able to select only one item when they want to without having to unselect everything that they selected or press a command button to clear it... (that's just ugly )
Here's what I thought of...
I think that if I were able to set the listbox's selection option to one of the multiples when I wanted to, that would work...
What I'm not sure on is how I can detect whether the Ctrl or Shift key being pressed while they are selecting the items in the listbox...
Any ideas on how I can do this? Maybe I'm looking at it all wrong... TELL ME PLEASE!
Thanks ,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
Jun 25th, 2004, 09:31 PM
#2
Fanatic Member
i don't know if this helps
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim s As String = "brown monkey hopes not to bark the wrong tree"
Dim ss() As String = Split(s, " ")
For Each s In ss
ListView1.Items.Add(s)
ListBox1.Items.Add(s)
Next
End Sub
Dim li As ListViewItem
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
li = ListView1.GetItemAt(e.X, e.Y)
End Sub
Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
li.BackColor = Color.DarkBlue
li.ForeColor = Color.White
li.Tag = "monkey" 'selected
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each li In ListView1.Items
li.BackColor = Color.White
li.ForeColor = Color.Black
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each li In ListView1.Items
If li.Tag = "monkey" Then
MessageBox.Show(li.Text)
End If
Next
End Sub
i recommend a listview
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
|