Set selected item on Combo Box based on text or value

ioustinos_sarris used Ask the Experts™
Hi there.
I am populating the values of a combo box at runtime and then want to set one of the values as selected.

this is how i populate the combobox
For Each s In [Enum].GetNames(GetType(super.GI1))
Next s

And then trying to set the selected
Me.gi1Combo.SelectedText = [Enum].GetName(GetType(super.GI1), Settings.GI1)
Me.gi1Combo.SelectedValue = [Enum].GetName(GetType(super.GI1), Settings.GI1)

neither works.
Settings.GI1 is declared as
Public GI1 As super.GI1

Thank you for anything you can do.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Try this:

Dim SelText as string =  [Enum].GetName(GetType(super.GI1), Settings.GI1)

 Me.gi1Combo.SelectedIndex = ComboBox1.FindStringExact(SelText)
Muhammad ZamanSoftware Development Lead

you have to do set as selected while you are populating combo box

For Each s In [Enum].GetNames(GetType(super.GI1))
         if Enum].GetNames(GetType(super.GI1) = "your specific value for selection" then
          // here you can write code for selection

Next s
IT Pro/Developer
Top Expert 2008
Since you're not binding anything you can simply to:
Me.gi1Combo.Text = [Enum].GetName(GetType(super.GI1), Settings.GI1)


Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial