Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pre-selecting a Value in a Combo Box

Status
Not open for further replies.

mcbigj

Programmer
Dec 14, 2001
83
0
0
US
Hello,
I'm doing a Windows c# app and I on the FormLoad() event I need to set a combo boxes selected item based on a value I pass it. I load the value from the database, it exists in the combo box as a value, so I need to set the combo box to display this value without it being manually selected.

I've done this before in VB.NET, but can't seem to make it work in C#. Here is the vb code that maybe one of you could translate into the C# version:


dim intVal as Int16 = (value)

Me.cboRPSDept.Items.Item(cboRPSDept.Items.IndexOf(cboRPSDept.Items.FindByValue(intVal))).Selected() = True


Any help with this would be appreciated.

John
 
I just found the solution.
It appears my VB.Net solution while it works, may be overkill. Here is how I did it in C#

int index = comboBox1.FindString(textBox2.Text);
comboBox1.SelectedIndex = index;

Hope this helps someone else.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top