Setting SelectedValue in a list control

  • Thread starter Thread starter Steve Enzer
  • Start date Start date
S

Steve Enzer

According to Microsoft's documentation, SelectedValue can be used to either
read or write to the SelectedValue property of a list control. I know I can
set it by binding the control to a datatable or array, but that seems like a
lot of work when I prefer to use a simple loop to add a small number of
items and values to a list control.

I've tried unsuccessfully to actually write to a control's SelectedValue
property. I suspect the problem is that I don't know how to specify the
index of the property.

Any ideas would be appreciated.

Thanks,
Steve Enzer
 
<< I've tried unsuccessfully to actually write to a control's SelectedValue
property. I suspect the problem is that I don't know how to specify the
index of the property. >>

You have to set the .SelectedItem property to a member of the .Items
collection. Here's an example:
List1.SelectedItem = List1.Items(2)

This selects the third item in the list (the index is zero-relative)

Karen Kenworthy
http://www.karenware.com/
 
Back
Top