Click here to Skip to main content
15,559,819 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.


Pass the value as a string.
cmdName.selectedItem = "globalName";
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..

<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
KIDYA 2-Dec-11 4:03am    
globalName is string variable in code.But not able to set selectedItem.
try this:

combobox.SelectedValue = globalName;
Share this answer
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)

  Print Answers RSS

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