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

[Solved] Using Columns From Two Tables

6 Answers 147 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Chris Ward
Top achievements
Rank 1
Chris Ward asked on 10 Jun 2011, 03:55 PM
Hi,

I am trying to use a RadGridView to display information from two tables.  tblProducts is a list of all avaiable products, and tblInstalledProducts contains information for which products each person has installed.  tblInstalledProducts holds a foreign key, ProductID.

I've tried traversing this relationship by binding to a tblInstalledProduct and setting the path to installedProduct.tblProduct.  I've found various mentions of using GridViewComboBoxColumn to bind to an alternate source (I don't mind the column being read-only).  There are also several recommendations to simply combine them into one datasource and bind to the new composed source.

I have not been able to get any of these methods to work correctly, so I'm wondering what is the easiest way to achieve this?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 10 Jun 2011, 04:00 PM
Hi Chris Ward,

Have you checked this online example.

The option matching your scenario is "Classic binding to objects" .. in the online sample we have CountryID instead of ProductID , however the concept is the same

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Ward
Top achievements
Rank 1
answered on 10 Jun 2011, 04:22 PM
Pavel,

Thank you for the speedy response, however I'm not sure how it applies to my situation.  The example appears to be an extremely simple grid with one column bound to one source.  I am trying to bind information from two separate tables to the same datagrid, not drop down lists.  If I have somehow missed your point please do let me know.

Thanks.
0
Vlad
Telerik team
answered on 10 Jun 2011, 04:31 PM
Hello,

To achieve your goal you need to prepare view model exposing desired properties from both tables or you can simply use template columns and show desired data in grid cells.

Regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Ward
Top achievements
Rank 1
answered on 10 Jun 2011, 04:56 PM
It appears that RadGridView does not support GridTemplateColumn as a valid type in its column collection.  Is there some dependancy I need to include in Silverlight for this to work?

This is what I am working with:
<telerik:RadGridView x:Name="InstalledProductsGridView"
                        DataContext="{StaticResource InstalledProductsDataSource}"
                        ItemsSource="{Binding DataView}"
                        IsBusy="{Binding IsBusy}"
                        AutoGenerateColumns="False">
  
    <!--Main product columns-->
     <telerik:RadGridView.Columns>
         <telerik:GridViewDataColumn Header="Device Name">
             <telerik:GridViewDataColumn.CellTemplate>
                 <DataTemplate>
                     <TextBlock DataContext="{StaticResource InstalledInfoDataSource}" Text="{Binding DeviceName}" />
                 </DataTemplate>
             </telerik:GridViewDataColumn.CellTemplate>
         </telerik:GridViewDataColumn>
         <telerik:GridViewDataColumn Header="Product Name" DataMemberBinding="{Binding ProductName, Mode=TwoWay}" />
         <telerik:GridViewDataColumn Header="Version" DataMemberBinding="{Binding ProductVersion, Mode=TwoWay, Converter={StaticResource VersionConverter}}" />
         <telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Description, Mode=TwoWay}" />
     </telerik:RadGridView.Columns>
     <telerik:RadGridView />

InstalledProductsDataSource returns a collection of tblProduct objects.
InstalledInfoDataSource returns a collection of tblInstalledProduct objects.
0
Vlad
Telerik team
answered on 13 Jun 2011, 07:21 AM
Hi,

 Indeed we don't have any special template column due to the fact that all grid column types have CellTemplate property. 

Kind regards,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Chris Ward
Top achievements
Rank 1
answered on 15 Jul 2011, 03:36 PM
For anyone else having this problem I did find the solution.  I turns out navigations properties are not serialied by default, which resulted in that relationship being null on the client side.  To fix this simply add the [Include] attribute to the property in the metadata.  This will allow bindings such as:
<TextBox Text="{Binding tblProduct.ProductName}" />
Tags
GridView
Asked by
Chris Ward
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Chris Ward
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or