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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Finding an item in a listview

Finding an item in a listview

Scheduled Pinned Locked Moved C#
question
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.
  • L Offline
    L Offline
    Lucy
    wrote on last edited by
    #1

    Hi I have a listview on my windows form with a details view. The listview has to columns and many items. These items and subitems are add to the listview in the form load event. The item are also put in s specific order. I then want to find an item in the second column and then select this item and give it focus. Can anyone give me any suggestions or where I can find good examples of listviews? Lucy

    S 1 Reply Last reply
    0
    • L Lucy

      Hi I have a listview on my windows form with a details view. The listview has to columns and many items. These items and subitems are add to the listview in the form load event. The item are also put in s specific order. I then want to find an item in the second column and then select this item and give it focus. Can anyone give me any suggestions or where I can find good examples of listviews? Lucy

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      have you googled it[^]

      -----

      L 1 Reply Last reply
      0
      • S SABhatti

        have you googled it[^]

        -----

        L Offline
        L Offline
        Lucy
        wrote on last edited by
        #3

        Hi thank you for the link. I was trying to go about this a different way but I found the answer before your reply using trial and error, Here is my form load event and the last if statement finds the item: RegistryKey key = Registry.LocalMachine.OpenSubKey("RegKey_test", true); RegistryKey k = key.OpenSubKey("Classification"); if (k != null) { string[] names = k.GetValueNames(); for (int i = 0; i < k.ValueCount; i++) { int values = Convert.ToInt32(k.GetValue(names[i], "")); ListViewItem item1 = new ListViewItem(); ListViewItem.ListViewSubItem item2 = new ListViewItem.ListViewSubItem(); item1.Text = names[i]; item2.Text = Convert.ToString(values); item1.SubItems.Add(item2); listView1.Items.Add(item1); } } if (key.GetValue("Threshold") != null) { string KeyValue = Convert.ToString(key.GetValue("Threshold", "")); ListViewItem itemFind = listView1.FindItemWithText(KeyValue, true, 0); if (itemFind != null) { itemFind.Selected = true; listView1.FocusedItem = itemFind; } } I am not sure if this is user friendly yet as the second column of the listview may be taken out so that the values cannot be seen by the user. I would then need a new ways to find the value needed to select the appropriate item. Lucy

        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