Listview --- What am I doing wrong?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Listview --- What am I doing wrong?

  1. #1
    Join Date
    Jul 2004
    Posts
    366

    Question Listview --- What am I doing wrong?

    Good Afternoon All,

    I'm trying to do what I thought would be very simple but I'm wrong appearantly. I'm trying to select an Item in a listview, then get the text from the item selected. If a certain item is selected I want to check all the items in the listview. Here's what I'm trying to do:

    Dim intRows As Integer = lvApplications.Items.Count
    Dim intRow As Integer = 0
    Dim intCnt As Integer = 0

    For intRow = 0 To intRows - 1
    Dim strItem As String = lvApplications.CheckedItems.Item(intRow).Text
    If strItem = "Select All" Then
    For intCnt = 0 To intRows - 1
    lvApplications.Items.Item(intCnt).Checked = True
    Next
    Exit Sub
    End If
    Next

    It works if I put it in a button, but when I try to run it from any event in the listview, it errors at the "strItem = " giving me an invalid index. I can't see what I'm doing wrong, I need new eyes.

    Any help would be great!!!

    Thanks in advance!

    jb

  2. #2
    Join Date
    Feb 2004
    Location
    Longueuil, Québec
    Posts
    577
    I cannot spot why what you are doing works on a Button but not in the ListView itself, but I would question the design idea here.

    If I understand well, selecting one of the items triggers a selection of all the items. Thus, selecting Select All selects everything... including the Select All item itself... which is probably useless as an item???

    It's not intuitive for a user to see a list from which to chose, and ending up with one of the item in the list being a function of the application instead of an real item. It might be appropriate, in a ComboBox, to put something such as "Select something..." as the default value of a ComboBox, because the user sees the instruction first, but it disappears once a selection is made. But on a list that stays on the screen, the Select All item is a nuisance.

    Why not simply have a CheckBox. Or a button Select All and another Unselect All?
    Jacques Bourgeois
    JBFI
    http://www3.sympatico.ca/jbfi/homeus.htm

  3. #3
    Join Date
    Jul 2004
    Posts
    366
    I was originally doing it in a button, but wanted to get it to work in the listview. No worries, looks like the button will do.

    Thanks JB!

Similar Threads

  1. Replies: 8
    Last Post: 01-20-2009, 02:22 PM
  2. Replies: 1
    Last Post: 09-16-2006, 07:37 PM
  3. ListView Control and Custom Sorting
    By Birhanu in forum VB Classic
    Replies: 0
    Last Post: 11-09-2001, 03:26 PM
  4. ListView Control and Custom Sorting
    By Birhanu in forum VB Classic
    Replies: 0
    Last Post: 11-09-2001, 03:26 PM
  5. Listview boxes
    By Kenneth in forum VB Classic
    Replies: 0
    Last Post: 04-24-2001, 11:04 AM

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