Results 1 to 5 of 5

Thread: Read selected rows in list box

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    25

    Read selected rows in list box

    I have a list box set to Multiselect = 1. Now I want to read through the collection of selected rows (e.g., for each...in...). However, I cannot find this method in any documention. Can someone help me with an example please.

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Read selected rows in list box

    Loop thru the ListBox, and if the current Item is .Selected, then do whatever.
    I post some pseudo code.

  3. #3

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: Read selected rows in list box

    Along these line:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim intCount As Integer
    3. Dim intIdx As Integer
    4.  
    5. intCount = List1.ListCount - 1
    6.  
    7.     For intIdx = 0 To intCount
    8.    
    9.         If List1.Selected(intIdx) Then MsgBox List1.List(intIdx)
    10.    
    11.     Next
    12.  
    13. End Sub

    Edit: If you intend to delete the selected items, then you must pass thru the ListBox backwards (intCount to 0 Step -1).
    Last edited by Bruce Fox; Nov 5th, 2006 at 06:06 PM.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    25

    Re: Read selected rows in list box

    The code example was a big help. Thank you. I guess I was incorrect in remembering that the selected items create a collection that can be worked with a "for all...in..." type of statement. I will use the example you listed.

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