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

I am using this code for selecting Item from Combobox but unfortunately not working.
Am i doing any mistake? or else suggest another way.

Code is :

cmbName.SelectedItem = globalName


cmbName contains globalName item already.But SelectedItem shows null.


Thanks
Posted

CSS
Pass the value as a string.
cmdName.selectedItem = "globalName";
or
use index value to select an item
cmdName.selectedIndex = 2;

index start from 0....
so index of first item will be 0....then 1 for second and so on..


here
XML
<pre lang="vb">Dim globalName As String = "dfd";

        ComboBox1.SelectedItem = globalName</pre>

if globalName is a variable declared by you then.... you should define a default value for that variable which is a item present in your combobox....
 
Share this answer
 
v2
Comments
KIDYA 2-Dec-11 4:03am    
globalName is string variable in code.But not able to set selectedItem.
try this:

C#
combobox.SelectedValue = globalName;
 
Share this answer
 
Comments
KIDYA 2-Dec-11 8:01am    
Not working...Still give SelectedValue is Null

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