Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a grid and I have added a combo box in this Datagrid, its source is a collection and filling the combos fine.

<ComboBox x:Name="cmb" SelectedValuePath="Name" Height="24" Width="150" Margin="126,87,228,200"> 
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{Binding Code}" FontWeight="Bold" Foreground="Black" 
                        <TextBlock Text="{Binding Name}" Foreground="Black"/>

I have to fill this grid and all combos from the DB, but unable to do this,

How can I achieve this?
Updated 7-May-13 0:01am

1 solution

You can use like this
SqlConnection conn = new SqlConnection("connection string");
SqlDataAdapter da = new SqlDataAdapter("your Query", conn);
DataSet ds = new DataSet();
da.Fill(ds, "tblName");
cmb.ItemsSource = ds.Tables[0].DefaultView;

If you are using MVVM, have a look at this...[^]
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