dropdown

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__
---_,>/'_------
(_) \(_)
---------------
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Dropdown 1
Browser Compatiablity 4
XML 6
LastIndexOf 3
Q 2
HashTable 3
FileStream 2
Help With MS Access 4

Top