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. Select an item in a listview

Select an item in a listview

Scheduled Pinned Locked Moved C#
helpdatabasequestion
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

    I have just added a listview onto a windows form. I have added 1 column to the listview and 4 items. I then set the View property to details. In the form load event of the windows form, I set the selected item to index 2 (item3) like this: listView1.Items[2].Selected = true; When the form loads item3 is selected as its back colour is blue but the first item has a dotted line around it. When I press the down arrow on my keyboard I should expect item4 to be selected. But instead item2 is selected as though I have pressed the up arrow. This must mean that item1 is the selected item when the form loads. Can anyone help me to solve this problem please? Lucy

    M 1 Reply Last reply
    0
    • L Lucy

      I have just added a listview onto a windows form. I have added 1 column to the listview and 4 items. I then set the View property to details. In the form load event of the windows form, I set the selected item to index 2 (item3) like this: listView1.Items[2].Selected = true; When the form loads item3 is selected as its back colour is blue but the first item has a dotted line around it. When I press the down arrow on my keyboard I should expect item4 to be selected. But instead item2 is selected as though I have pressed the up arrow. This must mean that item1 is the selected item when the form loads. Can anyone help me to solve this problem please? Lucy

      M Offline
      M Offline
      mav northwind
      wrote on last edited by
      #2

      You're mixing up "selected" and "focused". The LVItem with the dotted border is the one containing the focus (exactly one at most), whereas the items with blue back color are each selected, i.e. ListViewItem.Selected will return true and they's contained in the SelectedItems collection of their LV.

      Regards, mav -- Black holes are the places where God divided by 0...

      L 1 Reply Last reply
      0
      • M mav northwind

        You're mixing up "selected" and "focused". The LVItem with the dotted border is the one containing the focus (exactly one at most), whereas the items with blue back color are each selected, i.e. ListViewItem.Selected will return true and they's contained in the SelectedItems collection of their LV.

        Regards, mav -- Black holes are the places where God divided by 0...

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

        Thank you! It is now clear to me the difference between selected and focused. To solve my problem I put this code under the selected item code in the form load event: listView1.FocusedItem = listView1.Items[2]; All works fine now. Thanks again. 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