Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Compare Listview Items and return the index

Compare Listview Items and return the index

Scheduled Pinned Locked Moved .NET (Core and Framework)
databasetutorial
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eatwork
    wrote on last edited by
    #1

    Hello everyone, I was wondering if anyone out there might know how to compare an entire listview item and return the index if one of the items matches. i have tried: Public Function FindItem(ByVal item As ListViewItem) As Integer Dim itm As ListViewItem For Each itm In Me.Items If itm.Equals(item) Then Return itm.Index Exit Function End If Next Return -1 End Function AND Public Function FindItem(ByVal item As ListViewItem) As Integer Dim itm As ListViewItem For Each itm In Me.Items If itm.Text = item.text Then Return itm.Index Exit Function End If Next Return -1 End Function The first one does not seem to work at all, and the second one works, but only checks the text value of the first column and does not seem to compare other column values of the listviewitem. Thank you eatwork

    J 1 Reply Last reply
    0
    • E eatwork

      Hello everyone, I was wondering if anyone out there might know how to compare an entire listview item and return the index if one of the items matches. i have tried: Public Function FindItem(ByVal item As ListViewItem) As Integer Dim itm As ListViewItem For Each itm In Me.Items If itm.Equals(item) Then Return itm.Index Exit Function End If Next Return -1 End Function AND Public Function FindItem(ByVal item As ListViewItem) As Integer Dim itm As ListViewItem For Each itm In Me.Items If itm.Text = item.text Then Return itm.Index Exit Function End If Next Return -1 End Function The first one does not seem to work at all, and the second one works, but only checks the text value of the first column and does not seem to compare other column values of the listviewitem. Thank you eatwork

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      eatwork wrote:

      the second one works, but only checks the text value of the first column and does not seem to compare other column values of the listviewitem

      That's because you did not write the code in such a way that it compares the values of the sub-items. ;P You'll need to iterate the SubItems collection of each ListViewItem, and compare their Text values. Josh

      E 1 Reply Last reply
      0
      • J Josh Smith

        eatwork wrote:

        the second one works, but only checks the text value of the first column and does not seem to compare other column values of the listviewitem

        That's because you did not write the code in such a way that it compares the values of the sub-items. ;P You'll need to iterate the SubItems collection of each ListViewItem, and compare their Text values. Josh

        E Offline
        E Offline
        eatwork
        wrote on last edited by
        #3

        Hi Josh, Thanks for the reply, I was hoping there would be a better way to go about that, but I guess I will have to go through the subitems. Thanks eatwork

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups