1

I don't get it to work to select a row of a listview at the beginning of my program.

        if (listView1.Items.Count > 0)
        {
            listView1.Items[0].Selected = true;
            listView1.Items[0].Focused = true;
        }

After running this snippet the first item is selected and focused.

listView1.Items[0].Selected
true 
listView1.Items[0].Focused 
true

after clicking manually an item in the listview I can walk thru this list with

listView1.Items[newPosition].Selected = true;

regards

masterchris_99
  • 2,683
  • 7
  • 34
  • 55
  • I understand that there's a language barrier, but it's currently _very_ unclear what you're asking. – David Dec 01 '10 at 14:54
  • Can you give us a better description of the behavior you're looking for? The code you posted should select a particular row of your listview. Is there something else you would like to accomplish? Or is this not working for you? – Cody Gray - on strike Dec 01 '10 at 14:58

1 Answers1

3

set listView1.HideSelection=false and listView1.Focus()

Bolu
  • 8,696
  • 4
  • 38
  • 70
  • thanks that works for me but the selection of the row is not "full". The row is selected with a low grey but if the row is selected complete it is blue – masterchris_99 Dec 01 '10 at 15:01
  • that is because your Form/listview is not focused – Bolu Dec 01 '10 at 15:06
  • @masterchris_99: That's correct; that is the expected behavior. The reason is because the listview does not currently have the focus. Just like the highlight around the edges of a button and similar effects on other controls, the blue selection indicates that your listview currently has the input focus. When the listview does *not* have the focus, but its selection is still visible, it turns gray instead of blue. Changing this is not recommended because it makes it very difficult for keyboard users to navigate your application. – Cody Gray - on strike Dec 01 '10 at 15:07
  • Your mind-reading skills are clearly better than mine. Good job figuring out the answer to the question. – Cody Gray - on strike Dec 01 '10 at 15:08
  • @ Cody: thank you, that's because I have met a similar requirement :) – Bolu Dec 01 '10 at 15:12