Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Need to SetSelectedItem for a single selection ListView

Hi,

I have a ListView set to single selection.  And when I look for SelectedItem I find a collection called SelectedItems.  How do I assign the value the the ListViewItem of my choice?


Thanks,
Bob
0
ba272
Asked:
ba272
3 Solutions
 
Alexandre SimõesManager / Technology SpecialistCommented:

Have you tried:
     lv.Items[index].Selected = true;

where index is the index of the item to select

Alex :p
0
 
Ravi SinghSenior Software EngineerCommented:
Hi, to set the selected item you have to set the Selected property of that ListViewItem to true but also then call the Select() method of the ListView, otherwise the selection doesnt occur, so you need something like:

listView1.Items[index].Selected = true;
listView1.Select();
0
 
existenz2Commented:
listView1.SelectedIndex = 0; works also.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now