Click here to Skip to main content
15,900,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using the code below, but not bind the Data in Combo Box. Please correct it.

C#
str = "select ItemCode,it_name from Items";
            com = new SqlCommand(str, con);
            ad = new SqlDataAdapter(com);
            ds = new DataSet();
            ad.Fill(ds, "Items");
            cmbItems.ValueMember = "ItemCode";
            cmbItems.DisplayMember = "it_name";
            cmbItems.DataSource = ds;
Posted
Comments
Raje_ 11-Apr-13 4:19am    
Add cmbItems.DataBind(); line after your cmbItems.DataSource = ds; line;
LebneizTech 11-Apr-13 5:06am    
it is Wndows Control.Here it is not.
Lebohang Danster 11-Apr-13 4:23am    
try make use of the dataBind() methods after specifying the datasource. cmbItems.DataBind()
LebneizTech 11-Apr-13 5:07am    
it is Wndows Control.Here it is not.

1 solution

You should have told this in your question that this is windows application.
It's ok. here you are storing your values in DataSet, and binding your dataset to combobox.

so Replace your last line of code with this code :-
C#
cmbItems.DataSource = ds.Tables["Items"];


Good luck.
 
Share this answer
 
Comments
LebneizTech 11-Apr-13 6:16am    
Thank You !
One more Question.
A.How to Bind ComboBoxColumn in DataGridView, not Add it into DataGridView, means I have a ComboBox in DataGridView. Only I have to display data in it.
In Web I used FindControl, but in Windows how can I Get ComboBox Control
B.How do I Fire Event in ComboBox of DataGridView.

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