ListViewItem question //C# newbie

  • Thread starter Thread starter genc ymeri
  • Start date Start date
G

genc ymeri

Hi,
I have a ListView with 3 ListViewItems on a C# form. I have button which
being clicked is suppose to select the Item #2.

How can I do that programatically ???

Thank You very much in advance.
 
Each ListViewItem has a property called Selected. If you set this true, the
item will be selected.

// Create a new ListView control.
ListView listView1 = new ListView();

// Create three items and three sets of subitems for each item.
ListViewItem item1 = new ListViewItem("item1",0);
ListViewItem item2 = new ListViewItem("item2",0);
ListViewItem item3 = new ListViewItem("item3",0);

//Add the items to the ListView.
listView1.Items.AddRange(new ListViewItem[]{item1,item2,item3});

// Select the 2nd item
item2.Selected = true;

See the following link for a complete explanation.

http://msdn.microsoft.com/library/e...listviewitemclassselectedtopic.asp?frame=true

Hope this helps.
 
Back
Top