Results 1 to 7 of 7

Thread: [RESOLVED] Getting Imageindex from Listview?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    68

    Resolved [RESOLVED] Getting Imageindex from Listview?

    I'm trying to get the Imageindex value of the image on each line of a Listview box, but nothing I've tried is working.

    Can someone point me in the right direction? I'm sure this is pretty simple.

    Thanks,
    ~ Chazz

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Imageindex from Listview?

    Loop through the Items collection and get the ImageIndex of each item.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    68

    Re: Getting Imageindex from Listview?

    I'm sure I'm doing this totally wrong, but this is what I have.

    Code:
    For i = 0 To ListView1.Items.Count - 1
    
    Dim value As String value = ListView1.Items(i).ImageKey MsgBox(value)
    Next
    The message box just gives me a blank message.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Imageindex from Listview?

    Did you set the ImageKey for the items? If the messages are blank then presumably not. Your origianl post says you want the ImageIndex, which is not the same thing. Setting one has no effect on the other.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    68

    Re: Getting Imageindex from Listview?

    This is what I'm using to add the items to the list. It seems to work ok, adds the image perfectly.

    Code:
    Dim LVitem As ListViewItem
    LVitem = New ListViewItem(" WEATHER: ", 6)

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Getting Imageindex from Listview?

    Sure it does. You're telling it which Image to use by index, not by key, so the ImageIndex property is set but not the ImageKey property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Aug 2008
    Posts
    68

    Re: Getting Imageindex from Listview?

    Thanks for your help jmcilhinney, I just started playing with Listviews yesterday, I've always used Listboxes so I've been trying to teach myself how to use Listviews now.

    GOT IT!
    Thanks jmcilhinney! I guess I was confusing Imageindex and Imagekey.

    Thanks again!
    Last edited by lithiumdm; Dec 16th, 2008 at 10:23 PM.

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