Select item in list view


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Select item in list view

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Select item in list view

    [Originally posted by Mike Walters]


    I want to select an item in a list view wail I am adding them˙  how do I do this?
    ˙ ˙ Do While Not rsSearch.EOF
    ˙ ˙ ˙ ˙ Recs = "Y"
    ˙ ˙ ˙ ˙ Set itemx = lvUserSearch.ListItems.Add(, , CStr(rsSearch!lastname))
    ˙ ˙ ˙ ˙ itemx.SubItems(1) = CStr(rsSearch!firstname & "")
    ˙ ˙ ˙ ˙ itemx.SubItems(2) = CStr(rsSearch!department & "")
    ˙ ˙ ˙ ˙ itemx.SubItems(3) = CStr(rsSearch!Email & "")
    ˙ ˙ ˙ ˙ itemx.SubItems(4) = CStr(rsSearch!billingaddress & "")
    ˙ ˙ ˙ ˙ itemx.SubItems(5) = CStr(rsSearch!UserID & "")
    ˙ ˙ ˙ ˙ itemx.SubItems(6) = CStr(rsSearch!Password & "")
    ˙ ˙ ˙ ˙ If itemx.SubItems(5) = highlighted Then lvUserSearch.ListItems.Item.Selected = True
    ˙ ˙ ˙ ˙ rsSearch.MoveNext
    ˙ ˙ Loop

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Select item in list view

    [Originally posted by Marty]

    There are two ways to do this:
    1. In your loop, add: itemx.Selected = True
    2. In your loop, add: Set lvUserSearch.SelectedItem = itemx

    I believe the second method is preferred by MS, but both seem to work.

    I also found that you can't see that the items are selected until the listview control has focus, so when done selecting the items (outside your loop) try adding:
    lvUserSearch.SetFocus

    I hope this helps,

    Marty

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Select item in list view

    [Originally posted by Jim]

    >>I also found that you can't see that the items are selected until the listview control has focus, so when done selecting the items (outside your loop) try adding<<

    Unchecking the hide selection options should fix that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center