To set selectedindex by value I have to use a 2 step process like this or is there a better way?
1st method:
Dim myValueListItem As ValueListItem = cboFrequency.Items.ValueList.FindByDataValue(FrequencyCode) If myValueListItem IsNot Nothing Then cboFrequency.SelectedIndex = cboFrequency.FindStringExact(myValueListItem.DisplayText) End If
2nd method:
cboFrequency.SelectedIndex = cboFrequency.Items.IndexOf(cboFrequency.Items.
ValueList.FindByDataValue(FrequencyCode))
Yes thanks, setting via SelectedItem is a better approach!
Hello Peter,
I wanted to know if you were able to solve your issue based on these suggestions or you still need help. Please let me know.
You could do something like the following assuming you have a ValueList with Items with values as follows:
1, 2, 3, 4
object FrequencyCode = new object(); FrequencyCode = 3; cboFrequency.SelectedItem = cboFrequency.ValueList.FindByDataValue(FrequencyCode);
Please feel free to let me know if I misunderstood you or if you have any other questions.
You have a method called FindByString/FindByExactString that's 1 pass to return the index.
Not sure why there is no method like this:
cboFrequency.SelectedIndex = cboFrequency.FindByDataValue(FrequencyCode))
Currently I am using this but as you can see it's a 2 pass and a little difficult to discover.
This seems fine to me. What is bothering you, it is a simple and accurate approach.