Results 1 to 5 of 5

Thread: ListView (A2K)

  1. #1
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ListView (A2K)

    I've been working on an application where I need to show data in a list box in different colors depending on certain criteria. I found out that the ListView control works perfectly in this situation!

    My problem, however, is that users need to have the ability to click on an item in the ListView to fill other fields on the form. In a list box I can use listbox.column(i, row) to extract the data I need from the list box.

    I can't seem to figure out how to do this same type of procedure with a ListView. I think it has something to do with referencing the ItemData property or the SubItemData property of the ListView but I can't figure out the proper syntax.

    Any help would be very much appreciated.

    Thanks!
    Sam

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ListView (A2K)

    With a list view named ListView1, the selected item is ListView1.SelectedItem (or ListView1.SelectedItem.Text).
    The text of the second column, i.e. the first subitem of the selected item is ListView1.SelectedItem.SubItems(1).
    That of the third column is ListView1.SelectedItem.SubItems(2) etc.

  3. #3
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListView (A2K)

    Hans,

    Thanks...that helped!

    One more thing:

    Using the Click Event I can do everything I need to do with the .selecteditem syntax you helped me with. However, my code won't run if a user presses the up or down arrows to select different rows in the ListView. I've tried using the KeyPress event to trap the directional keys but KeyPress doesn't seem to recognize these key presses.

    Then I came across the ItemClick event which I think triggers every time the selected value in the ListView is changed. I think this is what I need but when I compile my code I get the following error message: "Procedure declaration does not match description of event or procedure having the same name."

    I only have one "Private Sub lvwDistPools_ItemClick(ByVal Item As ListItem) "where lvwDistPools is the name of my ListView so there isn't a same-name type conflict anywhere.

    So, two questions:
    1. Is the ItemClick event what I need to work with so that my code will run anytime the ListView selection changes (via mouse click or directional key press)?
    2. If the ItemClick is the right event to work with then why do I get that procedure declaration error message?

    Thanks for the help!
    Sam

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: ListView (A2K)

    1) The ItemClick event fires when the user clicks on an item in the first column of the list view, or changes the selected item another way, for example using the arrow keys. It doesn't fire if the user clicks in any of the other columns (the Click event does fire in that situation).

    2) Change the procedure declaration to

    Private Sub lvwDistPools_ItemClick(ByVal Item As Object)

    (The implementation of ActiveX controls in Access is somewhat primitive and the documentation, if available at all, is not always correct)

  5. #5
    Star Lounger
    Join Date
    Jan 2002
    Location
    Washington State
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: ListView (A2K)

    Perfect! Works beautifully!

    Yeah, it's too bad documentation is so hard to find for ActiveX controls.

    Thanks again!
    Sam

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •