Click here to Skip to main content
15,557,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I have one string which holds value and i want to search that value from combobox and assign as selected item.

i am using following code but not working.is there any other way?

cmbCameraName contains items: Add,Delete,Modify

C#
string CameraName="Add";
int index =Convert.ToInt16(cmbCameraName.FindName(CameraName));
                      cmbCameraName.SelectedIndex = index;



Thanks
Posted
Updated 24-Nov-11 19:54pm
v2
Comments
rajeevcapgeminiindia 25-Nov-11 1:37am    
In comboBox you can store two things
-Display Text
-Combo Value

If you select display Text, then write following code to get Combo Value
comboBox1.SelectedValue
Sergey Alexandrovich Kryukov 25-Nov-11 2:01am    
Did you try to see the value of index under debugger. -1? 0?
--SA

1 solution

are you sure that your combobox has a value?

if it has a value then try this:

C#
int index =Convert.ToInt16(cmbCameraName.FindName(CameraName));
                      cmbCameraName.SelectedIndex = index;



...
if ur still encountering a probelm ask me,,,

thanks hope it helps. :)
 
Share this answer
 
Comments
KIDYA 25-Nov-11 1:38am    
Still encountering a problem.I am loading values into Combobox before calling this code and it contains values.
D K N T H 25-Nov-11 1:51am    
try this:


int index =Convert.ToInt16(combobox.selectedvalue = index);
KIDYA 25-Nov-11 2:07am    
Initially index is on -1.No any value is selected.above code will work for it?
D K N T H 25-Nov-11 2:18am    
try this:

string CameraName="Add";
int index =Convert.ToInt16(cmbCameraName.SelectedValue = CameraName));

mark this as an answer if it helps you..

thanks..
KIDYA 25-Nov-11 5:44am    
Not worked..gives an error input string is not in correct format

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900