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

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


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

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

1 solution

You can use like this
C#
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...
http://blog.cylewitruk.com/2010/09/wpf-combobox-and-databinding-datacontext-itemssource-displaymemberpath-selecteditem-selectedvalue-selectedvaluepath/[^]
 
Share this answer
 
v2

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