This is a migrated thread and some comments may be shown as answers.

Binding a DataSet to a GridviewComboBoxColumn

2 Answers 108 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Christophe
Top achievements
Rank 1
Christophe asked on 10 Jun 2014, 12:32 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Dimitrina
Telerik team
answered on 12 Jun 2014, 08:01 AM
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.
 
0
Christophe
Top achievements
Rank 1
answered on 12 Jun 2014, 08:09 AM
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 !
Tags
GridView
Asked by
Christophe
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Christophe
Top achievements
Rank 1
Share this question
or