Click here to Skip to main content
15,877,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,

I have a ComboBox in a Windows Form and this ComboBox binding it's data from the database. I want when the windows form loaded the first item appear and is selected in the ComboBox.

How can I do that?

Thanks.
Posted
Updated 4-Feb-11 11:46am
v3

The easy answer to this depends on how your ComboBox is bound to the database.

The general answer is to position the database table to the record with the value you want to see in the ComboBox.
 
Share this answer
 
Comments
Yasser El Shazly 4-Feb-11 17:40pm    
ItemsSource="{Binding}"
Cls_Medications Med = new Cls_Medications();

DataSet ds = new DataSet();

#region ---binding med Latin Names in Cmx_Latin---
ds = Med.List_AllMedLatinNames();
this.Cmx_Latin.DataContext=ds.Tables["Med"].DefaultView;
//-----------------------------------------------
this.Cmx_Latin.DisplayMemberPath = ds.Tables["Med"].Columns["Name_latin"].ToString();
//------------------------------------------------
this.Cmx_Latin.SelectedValuePath = ds.Tables["Med"].Columns["Name_latin"].ToString();
#endregion
Henry Minute 4-Feb-11 17:48pm    
You didn't say that this was a WPF problem. I have altered your tags to indicate this.

I hope that someone can help with your problem.
Try this way

DataRow nRow = ds.Tables["Med"].NewRow();
         nRow["Med"] = "List All";
         nRow["Med"] = "0";
         ds.Tables["Med"].Rows.InsertAt(nRow, 0);
this.Cmx_Latin.DataContext=ds.Tables["Med"].DefaultView; 
 
Share this answer
 

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