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

[Solved] How to:binding GridViewComboBoxColumn's ItemSource with CollectionViewSource

3 Answers 383 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.
lee hom
Top achievements
Rank 1
lee hom asked on 20 Aug 2010, 02:35 PM

Hi telerik,
    There has four tables:School--->College--->Department---->Class,all of them are 1:n relationship.
    Now,I use RadGridView DomainDataSource and CollectionViewSource to show the data,like this:

        <telerik:RadGridView ItemsSource="{Binding ElementName=classDomainDataSource, Path=Data}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewComboBoxColumn ItemsSource="{Binding ElementName=schoolDomainDataSource, Path=Data}" DisplayMemberPath="Name" Header="School" DataMemberBinding="{Binding Department.College.School}">
                </telerik:GridViewComboBoxColumn>
               
                <telerik:GridViewComboBoxColumn ItemsSource="{Binding Source={StaticResource schoolCollegeViewSource}}" DisplayMemberPath="Name" Header="College" DataMemberBinding="{Binding Department.College}" />
               
                <telerik:GridViewComboBoxColumn ItemsSource="{Binding Source={StaticResource schoolCollegeDepartmentViewSource}}" DisplayMemberPath="Name" Header="Department" DataMemberBinding="{Binding Department}" />
                <telerik:GridViewDataColumn Header="Class" DataMemberBinding="{Binding Name}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

DomainDataSrouce and ColltionViewSource:

 

     <UserControl.Resources>
        <CollectionViewSource x:Key="schoolCollegeViewSource" Source="{Binding Path=Data.College, ElementName=schoolDomainDataSource}" />
        <CollectionViewSource x:Key="schoolCollegeDepartmentViewSource" Source="{Binding Path=Department, Source={StaticResource schoolCollegeViewSource}}" />
    </UserControl.Resources>

        <riaControls:DomainDataSource AutoLoad="True" Name="schoolDomainDataSource" QueryName="GetSchoolQuery">
            <riaControls:DomainDataSource.DomainContext>
                <my:DS />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

        <riaControls:DomainDataSource AutoLoad="True" Name="classDomainDataSource" QueryName="GetClassQuery" >
            <riaControls:DomainDataSource.DomainContext>
                <my:DS />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>


the problem is: GridViewComboBoxColumn do not work.....

thanks.

here is the project and database

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Aug 2010, 12:49 PM
Hi lee hom,

In your code I see that you are using ElementName binding . Unfortunately we do not support ElementName binding for the ItemsSource of the combo column . Since this binding happens at cell level , and cells are virtualized , ElementNameBinding will not be reliable.

As a solution I may offer you to expose the ItemsSource for the combo column in a static resource and use binding syntax like :

ItemsSource = {Binding .., Source={StaticResource.....}.

Let me know in case you have troubles implementing this approach .

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
lee hom
Top achievements
Rank 1
answered on 26 Aug 2010, 10:34 AM
ok,i changed the code like this:

<UserControl x:Class="Silverlight.Grid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices" xmlns:my="clr-namespace:Web">

    <UserControl.Resources>

        <riaControls:DomainDataSource AutoLoad="True" x:Key="ddsSchool"  Name="schoolDomainDataSource" QueryName="GetSchoolQuery">
            <riaControls:DomainDataSource.DomainContext>
                <my:DS />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>

        <CollectionViewSource x:Key="schoolCollegeViewSource" Source="{Binding Path=Data.College, Source={StaticResource ddsSchool}}" />
       
        <CollectionViewSource x:Key="schoolCollegeDepartmentViewSource" Source="{Binding Path=Department, Source={StaticResource schoolCollegeViewSource}}" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <telerik:RadGridView ItemsSource="{Binding ElementName=classDomainDataSource, Path=Data}" AutoGenerateColumns="False">
            <telerik:RadGridView.Columns>
                <telerik:GridViewComboBoxColumn
                    Header="School"
                    DataMemberBinding="{Binding Department.College.School.ID, Mode=OneTime}"
                    ItemsSource="{Binding Data, Source={StaticResource ddsSchool}}"
                    DisplayMemberPath="Name"
                    SelectedValueMemberPath="ID"  />

                <telerik:GridViewComboBoxColumn
                    Header="College"
                    DataMemberBinding="{Binding Department.College.ID,Mode=OneTime}"
                    ItemsSource="{Binding Source={StaticResource schoolCollegeViewSource}}"
                    DisplayMemberPath="Name"
                    SelectedValueMemberPath="ID"  />

                <telerik:GridViewComboBoxColumn
                    Header="Department"
                    DataMemberBinding="{Binding DepartmentID}"
                    ItemsSource="{Binding Source={StaticResource schoolCollegeDepartmentViewSource}}"
                    DisplayMemberPath="Name"
                    SelectedValueMemberPath="ID">
                </telerik:GridViewComboBoxColumn>

                <telerik:GridViewDataColumn
                    Header="Class"
                    DataMemberBinding="{Binding Name}" />
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

        <riaControls:DomainDataSource AutoLoad="True" Name="classDomainDataSource" QueryName="GetClassQuery" >
            <riaControls:DomainDataSource.DomainContext>
                <my:DS />
            </riaControls:DomainDataSource.DomainContext>
        </riaControls:DomainDataSource>
    </Grid>
</UserControl>



now,the problem is: i can't select any item in combobox
0
Maya
Telerik team
answered on 31 Aug 2010, 02:02 PM
Hello lee hom,

The settings in your xaml file should be similar to:

<UserControl.Resources>
  <riaControls:DomainDataSource x:Key="customers" Name="customerDomainDataSource"  QueryName="GetOrdersQuery" AutoLoad="True" >
       <riaControls:DomainDataSource.DomainContext>
                <local:CustomersDomainContext />
       </riaControls:DomainDataSource.DomainContext>
  </riaControls:DomainDataSource>
</UserControl.Resources>

 
<telerik:GridViewComboBoxColumn Header="Comboxcolumn"
  DataMemberBinding="{Binding CustomerID}"                                                     SelectedValueMemberPath="{Binding CustomerID}"                                        
    
DisplayMemberPath="{Binding CompanyName}"                                                     
  ItemsSource="{Binding Data, Source={StaticResource customers}}" />

Please let me know if it resolves your issue or you need a sample application for a further reference. If this does not meet your requirements, please fix the link towards your project as so far I am not able to download anything from there. Or else you can open a support ticket and resend the application.

Best wishes,
Maya
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
Tags
GridView
Asked by
lee hom
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
lee hom
Top achievements
Rank 1
Maya
Telerik team
Share this question
or