Results 1 to 2 of 2

Thread: Listbox Select Multiple

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2001
    Location
    USA
    Posts
    1,026

    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?

  2. #2
    Fanatic Member brown monkey's Avatar
    Join Date
    Jun 2004
    Location
    Cebu
    Posts
    552
    i don't know if this helps
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.       Dim s As String = "brown monkey hopes not to bark the wrong tree"
    3.       Dim ss() As String = Split(s, " ")
    4.       For Each s In ss
    5.          ListView1.Items.Add(s)
    6.          ListBox1.Items.Add(s)
    7.       Next
    8.    End Sub
    9.  
    10.    Dim li As ListViewItem
    11.    Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
    12.       li = ListView1.GetItemAt(e.X, e.Y)
    13.    End Sub
    14.  
    15.    Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
    16.       li.BackColor = Color.DarkBlue
    17.       li.ForeColor = Color.White
    18.       li.Tag = "monkey" 'selected
    19.    End Sub
    20.  
    21.    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    22.       For Each li In ListView1.Items
    23.          li.BackColor = Color.White
    24.          li.ForeColor = Color.Black
    25.       Next
    26.    End Sub
    27.  
    28.    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    29.       For Each li In ListView1.Items
    30.          If li.Tag = "monkey" Then
    31.             MessageBox.Show(li.Text)
    32.          End If
    33.       Next
    34.    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
  •  



Click Here to Expand Forum to Full Width