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

Binding a dataset to GridView

3 Answers 220 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gil
Top achievements
Rank 1
Gil asked on 11 Feb 2013, 11:56 PM
I'm trying to bind some data from an SQL Server database to a RadGridView.  I'm grabbing the data and storing it in a dataset and I've tested this to see that the data is coming in properly.  I've tried setting the ItemsSource and the DataContext with:
Grid.ItemsSource = ds.Tables[0].DefaultView;               

But the data never loads in.  This is my XAML code:

 <telerik:RadGridView Name="Grid" Grid.Row="2" Grid.ColumnSpan="3"  HorizontalAlignment="Center" VerticalAlignment="Bottom"
                             AlternateRowBackground="AliceBlue" SelectionMode="Multiple"
                             AutoGenerateColumns="False" MinHeight="300" MinWidth="800"  CanUserResizeColumns="True" CanUserResizeRows="True"
                             FilteringMode="FilterRow"  IsFilteringAllowed="True"  CanUserSortColumns="True" GridLinesVisibility="Both"
                             DataLoadMode="Asynchronous"  >
            <telerik:StyleManager.Theme>
                <telerik:Windows8Theme/>
            </telerik:StyleManager.Theme>
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Width="40" Header="Add" DataMemberBinding="{Binding Add}" IsGroupable="False" IsFilterable="True" >                                
                    </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Width="75" Header="Qty"  IsGroupable="False" IsFilterable="True">
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn Width="75" Header="Catalog Number" DataMemberBinding="{Binding Catalog_No}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="200" Header="Description" DataMemberBinding="{Binding Description}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="Price" DataMemberBinding="{Binding Price}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="Min" DataMemberBinding="{Binding Min}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="# avl" DataMemberBinding="{Binding Available}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="Size" DataMemberBinding="{Binding Size}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="Color" DataMemberBinding="{Binding Color}" IsGroupable="False" IsFilterable="True"/>
                <telerik:GridViewDataColumn Width="75" Header="Style" DataMemberBinding="{Binding Style}" IsGroupable="False" IsFilterable="True"/>
            </telerik:RadGridView.Columns>
            
        </telerik:RadGridView>

So am I doing something wrong here or do I have to change the way I'm loading in the grid data?  In this case, it would not be impractical to load the data in and fill the grid view by looping through the data, but I'm going to be using the gridview in other places as well where I'll have to load in too much data for that to be a practical solution.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 12 Feb 2013, 07:04 AM
Hi,

 Can you verify if the same DataSet can be bound normally to standard WPF DataGrid? Do you have any binding expression errors in the Visual Studio output window?

Regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Gil
Top achievements
Rank 1
answered on 13 Feb 2013, 04:31 AM
I'm able to see the data in a DataGrid.

I used the following code to set the dataset to the grid
this.TestDataGrid.DataContext = ds.Tables[0].DefaultView;
and this code for the xaml:
<DataGrid Name="TestDataGrid" ItemsSource="{Binding}" Grid.Row="0" >
     
</DataGrid>
0
Vlad
Telerik team
answered on 13 Feb 2013, 07:11 AM
Hello,

 Unfortunately I'm not sure what's going on in your case. Please open support ticket and send us small project demonstrating the problem. We will review your scenario and we will provide more info what is causing the problem. 

Greetings,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Gil
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Gil
Top achievements
Rank 1
Share this question
or