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

Can't get GridViewComboBoxColumn to work

3 Answers 148 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 03 May 2011, 05:56 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 04 May 2011, 07:38 AM
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
0
Mark
Top achievements
Rank 1
answered on 04 May 2011, 05:09 PM
Maya:

I just copied your code:

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

and it worked perfectly.  Thanks very much!

Mark
0
Gio
Top achievements
Rank 1
answered on 24 Nov 2011, 04:14 PM

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>
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Maya
Telerik team
Mark
Top achievements
Rank 1
Gio
Top achievements
Rank 1
Share this question
or