Binding a DataSet to a GridviewComboBoxColumn

3 posts, 1 answers
  1. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 10 Jun 2014 Link to this post

    Hello,

    I've searched for a while but didn't find anything useful about it.

    I've a dataset, filled with an SQL query which contains a table of many records, and a gridView with a comboboxcolumn. I try to bind my comboboxcolumn with my dataset, but it only displays the first row, in my whole column. For example, if I have 400 records, it displays 400 times the first record.

    Here's my code in my .xaml :

    <telerik:RadGridView HorizontalAlignment="Left"
                                 VerticalAlignment="Top"
                                 ItemsSource="{Binding dataSetCameras}"

    etc, and :

    <telerik:GridViewComboBoxColumn Header="Cameras"
                                                    UniqueName="Camera"
                                                    DataMemberBinding="{Binding reference}"
                                                    DisplayMemberPath="Camera"
                                                    SelectedValueMemberPath="Camera"
                                                    HeaderTextAlignment="Center"
                                                    EditTriggers="CellClick"
                                                    Width="*">
                        <telerik:GridViewComboBoxColumn.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.RowDefinitions>
                                        <RowDefinition />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>
                                    <TextBlock Grid.ColumnSpan="2" Text="{Binding reference}" />
                                    <StackPanel Grid.Row="1" Orientation="Horizontal">
                                        <TextBlock Foreground="#FF356EA6" Text="{Binding sold}" />
                                        <TextBlock Text=", " />
                                        <TextBlock Foreground="#FF356EA6" Grid.Column="1" Text="{Binding broken}" />
                                        <TextBlock Text=", " />
                                        <TextBlock Foreground="#FF356EA6" Grid.Column="2" Text="{Binding stolen}" />
                                    </StackPanel>
                                </Grid>
                            </DataTemplate>
                        </telerik:GridViewComboBoxColumn.ItemTemplate>

    And in my .cs :

    ((GridViewComboBoxColumn)this.gridViewCameras.Columns["Camera"]).ItemsSource = datas.dataSetCameras.Tables;

    Did I miss something ? And yes, I'm sure that my dataset is filled with the right values.

    Thanks for your help !
  2. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 12 Jun 2014 Link to this post

    Hello,

    I tested binding GridViewComboBoxColumn to a DataTable.DefaultView and it worked fine, populating all the items available in my table. 
    Would you please try:
    ((GridViewComboBoxColumn)this.gridViewCameras.Columns["Camera"]).ItemsSource = datas.dataSetCameras.Tables.DefaultView;

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Christophe
    Christophe avatar
    16 posts
    Member since:
    May 2014

    Posted 12 Jun 2014 in reply to Dimitrina Link to this post

    Hello,

    Thanks for your answer, I've finally find out that it works if I write :
    ((GridViewComboBoxColumn)this.gridViewCameras.Columns["Camera"]).ItemsSource = donnees.dataSetCameras.Tables[0].DefaultView;

    I only added [0] in my value but I'd try your solution too. I've written that moments ago but it didn't work, maybe because I forgot to add / change something in my xaml beside. That's why I didn't find the answer sooner.

    Thanks !
Back to Top