Click here to Skip to main content
15,068,678 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,


Im Add Some Items To Combobox Like
C#
Combobox cbox = new ComboBox();
cbox.Items.Add("A");
cbox.Items.Add("B");
cbox.Items.Add("C");
cbox.Items.Add("D");
cbox.Items.Add("E");




Assiging
C#
cbox.Text = Value From Database (Value May Be "A",or "B" or "C" or "D");

But In Combobox Text Display I Cannot See The Value?
Posted
Updated 21-Jul-13 20:00pm
v2
Comments
   
What prevents you from just reading the documentation?
—SA

Use this Code For binding Combobox with database records
C#
public void bindd()
       {
           string str = "Select name,payment_id From payment";
           SqlCommand com = new SqlCommand(str, sconn);
           SqlDataAdapter sqlda = new SqlDataAdapter(com);
           DataSet ds = new DataSet();
           sqlda.Fill(ds, "payment");
           combopaymenttype.DataSource = ds.Tables["payment"].DefaultView;
           combopaymenttype.DisplayMember = "name";
           combopaymenttype.ValueMember = "payment_id";
       }
   
Comments
anee146 22-Jul-13 1:41am
   
Combobox Contain Random Value , Collection Is Not Added From The Database,

Database Value Is Based On The Indivudal Record
Hi. in WPF you must first Bind Control.Property to DataBase.
in here you must :
Combobox.ItemsSource=From Db;
in xaml:
<combobox itemssource="{Biding}" displaymemberpath="{Biding yourFieldInDB}">
good luck
   

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