How to: Select an Item in the Windows Forms Lis...
Windows Forms Programming
How to: Select an Item in the Windows Forms ListView Control

This example demonstrates how to programmatically select an item in a Windows Forms ListView control. Selecting an item programmatically does not automatically change the focus to the ListView control. For this reason, you will typically want to call the Focus method when selecting an item.

Visual Basic
me.ListView1.Focus()
me.ListView1.Items(0).Selected = True
C#
this.listView1.Focus();
this.listView1.Items[0].Selected = true;

This example requires:

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Changing the Focused ListViewItem along with the Selected ListViewItem      Davey Boy Crocky   |   Edit   |   Show History

When you set the Selected property to select a ListViewItem like this:

this.listView1.Items[0].Selected = true;

you can end up with one item in the list view selected and another one focused. This can cause strange results when trying to use the arrow keys after programmatically selecting a ListViewItem. To avoid this glitch, use this code:

this.listView1.Items[0].Selected = true;
this.listView1.Items[0].Focused = true;
Tags What's this?: Add a tag
Flag as ContentBug
Processing
Page view tracker