Pre Selecting an item in ListView?

  • Thread starter Thread starter Bob Geltz
  • Start date Start date
B

Bob Geltz

I am able to populate a ListView with several detail lines (several
columns). When finished, I would like to pre-select the first item in the
list (before the user interacts with the list). This way, if a user clicks
on the OK button, there will be a default selection.

I know how to use ListView.SelectedItems to get the selection,
I just don't know how to make an item be selected without the
user actually clicking on a line.

For a ListBox, I could use ListBox.SetSelected (0, true). I am looking
for an equivalent function for ListView.

Any suggestions? This has to be a trivial problem, but I cannot find
anything in the documentation that tells me what property to set (or how to
set it)

Thanks..
 
Hi Bob,

The items in a listview are a collection of
listviewitems. They can be accessed individually by
specifying which item you want to change, like this:

lsvTest.Items[0].Selected = true;

where the index if Items is the index of the item in the
list. So this code will select the first item in the
list.

Doug
 
Back
Top