Can't get GridViewComboBoxColumn to work

4 posts, 1 answers
  1. Mark
    Mark avatar
    19 posts
    Member since:
    Dec 2010

    Posted 03 May 2011 Link to this post

    I am not able get a GridViewComboBox column to work.  I have two RadDomainDataSources on my page; one for the grid and another for the combo box source.  I cannot get the combo box to populate.  It is also not showing the field in the grid that I am trying to populate with the combo box.

    The field in the grid that I am trying to populate is "PLCategoryID".
    The Display field for the combo box  is "CategoryDescription".
     
    I set up the RadDomainDataSource for the combo box as a static resource, as described in one of your articles.  (I also added a "test" grid that uses the same RadDomainDataSource as the combo box to be sure that the data was being retrieved properly, and this is working correctly.)
    Here is the code for the page:

    <navigation:Page x:Class="PE2.Views.SetupPages.AccountMapping.PLMapAccountsToCategories" 
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
               xmlns:server="clr-namespace:PE2.Web.Services"
               xmlns:telerikDragDrop="clr-namespace:Telerik.Windows.Controls.DragDrop;assembly=Telerik.Windows.Controls" 
               mc:Ignorable="d"
               xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"       
               d:DesignWidth="779" d:DesignHeight="480"
               Title="PLMapAccountsToCategories Page" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
        <UserControl.Resources>
            <telerik:RadDomainDataSource 
                x:Key="radDomainDataSourcePLCategory" Width="0" QueryName="GetPLCategories" AutoLoad="True">
                    <telerik:RadDomainDataSource.DomainContext>
                        <server:PEDataDomainContext/>
                    </telerik:RadDomainDataSource.DomainContext>
            </telerik:RadDomainDataSource
        </UserControl.Resources>
      
        <Grid x:Name="LayoutRoot" Background="LightGreen">
            <Grid.RowDefinitions>
                <RowDefinition Height="404*" />
                <RowDefinition Height="76*" />
            </Grid.RowDefinitions>
            <StackPanel Height="255" HorizontalAlignment="Left" Margin="12,12,0,0" Name="stackPanel1" VerticalAlignment="Top" Width="755">
                <telerik:RadDomainDataSource Height="0" Name="radDomainDataSourceChartOfAccounts" Width="0" QueryName="GetChartOfAccounts" AutoLoad="True">
                    <telerik:RadDomainDataSource.DomainContext>
                        <server:PEDataDomainContext/>
                    </telerik:RadDomainDataSource.DomainContext>
                </telerik:RadDomainDataSource>
                 
            </StackPanel>
            <Button Content="Load Accounts" Height="23" HorizontalAlignment="Left" Margin="34,23,0,0" Name="buttonLoadAccounts" VerticalAlignment="Top" Width="101" Grid.Row="1" />
            <telerik:RadGridView Name="radGridViewChartOfAccounts" Margin="12,23,12,0" CanUserSelect="False" ItemsSource="{Binding ElementName=radDomainDataSourceChartOfAccounts, Path=DataView}" AutoGenerateColumns="False" Height="180" VerticalAlignment="Top" DataLoaded="radGridViewChartOfAccounts_DataLoaded">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="Account No." DataMemberBinding="{Binding AccountNo}"/>
                    <telerik:GridViewDataColumn Header="Account Name"  DataMemberBinding="{Binding AccountName}"/>
                    <telerik:GridViewDataColumn Header="Account Description"  DataMemberBinding="{Binding AccountDesc}"/>
                    <telerik:GridViewDataColumn Header="Account Type"  DataMemberBinding="{Binding AccountType}"/>
                    <telerik:GridViewComboBoxColumn 
                        Header="PL Category"  
                        DataMemberBinding="{Binding PLCategoryID, Mode=TwoWay}"
                        DisplayMemberPath="CategoryDescription"
                        SelectedValueMemberPath="PLCategoryID" IsAutoGenerated="False" 
                        ItemsSourceBinding="{Binding Source={StaticResource radDomainDataSourcePLCategory}}" />
                    <telerik:GridViewDataColumn Header="P&L" DataMemberBinding="{Binding PLCategoryID, Mode=TwoWay}"/>
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
            <telerik:RadGridView Name="test" ItemsSource="{Binding Path=DataView}" Margin="12,209,12,30" Grid.RowSpan="2" DataContext="{Binding Source={StaticResource radDomainDataSourcePLCategory}}">
      
            </telerik:RadGridView>
        </Grid>
    </navigation:Page>

    Any help wwould be greatly appreciated.

    Thanks,
    Mark
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 May 2011 Link to this post

    Hi Mark,

    ItemsSourceBinding of the GridViewComboBoxColumn is used when the source for that column is property of the business object for the grid. For example if in your case the data item of the RadGridView is "Account", this class needs to expose a "Categories" property together with "AccountName","AccountNo", etc.
    As it is in your case, you need to set the ItemsSource of the column in the same manner as the one of the grid. Based on the code provided, I believe it should be:

    <telerik:GridViewComboBoxColumn
                        Header="PL Category" 
                        DataMemberBinding="{Binding PLCategoryID, Mode=TwoWay}"
                        DisplayMemberPath="CategoryDescription"
                        SelectedValueMemberPath="PLCategoryID" IsAutoGenerated="False"
                        ItemsSource="{Binding DataView, Source={StaticResource radDomainDataSourcePLCategory}}" />

    Still, I am sending you a sample project for further reference.
      


    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
  3. Mark
    Mark avatar
    19 posts
    Member since:
    Dec 2010

    Posted 04 May 2011 Link to this post

    Maya:

    I just copied your code:

    ItemsSource="{Binding DataView, Source={StaticResource radDomainDataSourcePLCategory}}" />

    and it worked perfectly.  Thanks very much!

    Mark
  4. Gio
    Gio avatar
    6 posts
    Member since:
    Jul 2011

    Posted 24 Nov 2011 Link to this post

    Resolved without static resource, but with cellTemplate.
    This template is used only for view data, while on edit is used the combo box.

    <tlk:GridViewComboBoxColumn Header="Categoria"
        ItemsSource="{Binding Path=EntitiesAdditional[Categorie], Mode=TwoWay}"
        DataMemberBinding="{Binding Path=Categorie, Mode=TwoWay}"
        DisplayMemberPath="Nome"
            <tlk:GridViewColumn.CellTemplate
                <DataTemplate
                    <TextBlock Text="{Binding Categorie.Nome}"></TextBlock
                </DataTemplate>  
            </tlk:GridViewColumn.CellTemplate
    </tlk:GridViewComboBoxColumn>
Back to Top