dropdown

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Q
How to do findbyValue search in a dropdown in WinForms??
And how to set the searched value as default selected in dropdown??


Need help


Thanks
Vinay



--
http://pathidotnet.blogspot.com
=====
vInAypAtHi
o__
---_,>/'_------
(_) \(_)
---------------
 
Hi Vinay,

The ComboBox control contains a list of objects -- this is slightly
different than the ASP.NET implementation. As such, there is no FindByValue
function available on the control -- you'll have to write a bit of code to
iterate through the items to find the one you are looking to get.

To set the selected item, you need to specify the value of the item you want
selected in the ComboBox.

For example:

DataTable dt = new DataTable("MyValues");
dt.Columns.Add("Value");
dt.Columns.Add("Display");

dt.Rows.Add(new object[] {"VA", "Virginia"});
dt.Rows.Add(new object[] {"WA", "Washington"});

this.comboBox1.DisplayMember = "Display";
this.comboBox1.ValueMember = "Value";
this.comboBox1.DataSource = dt;

this.comboBox1.SelectedValue = "WA";


Hope that helps,

-Paul
 
Back
Top