set dropdownlistbox value based on variable

evaleah

Well-known member
Joined
May 14, 2003
Messages
55
I think there was another post about this in this forum, so I aplogize if I am repeating. I did a pretty exhaustive search and came up with nothing, so I am going ahead and asking.

I have a populated dropdownlistbox. In a later subroutine I want to pick one of the items from the list and set that as the selected item. I want to select the item by the selecteditem.value.

So, I tried:
Code:
DropDownList.SelectedItem.Value = MyVariable

This resulted in setting the value of the item that was already selected to my variable. When I wanted to have the item.value that matched my variable be the one selected.

Thanks!
Eva
 
Well, this seems to always happen to me here. I search and search, finally post here, and then find the answer in seconds.

Just in case anyone is interested this is what I did:
Code:
With DropDownList1
       .SelectedIndex = .Items.IndexOf(.Items.FindByValue(MyVariable))
End With
 
Back
Top