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

Trouble setting ItemSource for RadComboBox within GridViewComboBoxColumn

3 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
christine
Top achievements
Rank 1
christine asked on 21 Oct 2011, 02:16 AM

I am binding programatically to a GridViewComboBoxColumn (see C# below) and I am using the CellTemplate to display a RadComboBox instead of text.  The problem is that I do not know how to set the ItemSource for the RadComboBox in order to make it work.  Thanks in advance for any help!

((GridViewComboBoxColumn)this.RadGridView_TrusteeLedgers.Columns[1]).ItemsSource = trustees;

<telerik:GridViewComboBoxColumn Header="Trustee" DataMemberBinding="{Binding TrusteeID}" SelectedValueMemberPath="TrusteeID" DisplayMemberPath="TrusteeCode" Width="60" Name="Trustee">
    <telerik:GridViewComboBoxColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadComboBox
                    ItemsSource="???"
                    SelectedValuePath="TrusteeID"
                    telerikControls:Theming.Theme="Office_Blue"
                    SelectedValue="{Binding TrusteeID, Mode=TwoWay}"
                    DisplayMemberPath="TrusteeCode" />
        </DataTemplate>
    </telerik:GridViewComboBoxColumn.CellTemplate>

3 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 21 Oct 2011, 07:07 AM
Hello Christine,

You can find the RadComboBox from each row as follows:

RadComboBox comboBox = row.ChildrenOfType<RadComboBox>().FirstOrDefault();

and set its ItemsSource afterwards. You can try working with RowLoaded event for example.

Regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
christine
Top achievements
Rank 1
answered on 21 Oct 2011, 05:52 PM
Thank you!  I was thinking maybe there was a way to reference the ItemSource of the GridViewComboBoxColumn in the RadComboBox  using XAML, maybe something like the code below (ItemsSource is still incorrect, this doesn't work but i'm not sure why). 

<telerik:GridViewComboBoxColumn Header="Trustee" DataMemberBinding="{Binding TrusteeID}" SelectedValueMemberPath="TrusteeID" DisplayMemberPath="TrusteeCode" Width="60" Name="Trustee">
    <telerik:GridViewComboBoxColumn.CellTemplate>
        <DataTemplate>
            <telerik:RadComboBox
                    ItemsSource="{Binding ElementName=Trustee, Path=ItemsSource}"
                    SelectedValuePath="TrusteeID"
                    telerikControls:Theming.Theme="Office_Blue"
                    SelectedValue="{Binding TrusteeID, Mode=TwoWay}"
                    DisplayMemberPath="TrusteeCode" />
        </DataTemplate>
    </telerik:GridViewComboBoxColumn.CellTemplate>
0
Maya
Telerik team
answered on 24 Oct 2011, 07:19 AM
Hi Christine,

Basically, you the ElementName binding will nor work when the element (RadComboBox in this case ) is defined in a DataTemplate. What you can try is to expose the class (probably your ViewModel) into the Resources section of your Grid/Window and use it as a StaticResource afterwards. 
For example:

<Window.Resources>
    <local:MyViewModel x:Key="MyViewModel" />
</Window.Resources>
 
 
<DataTemplate>
            <telerik:RadComboBox
                    ItemsSource="{Binding MyItemsSource, Source={StaticResource MyViewModel}}"
                    SelectedValuePath="TrusteeID"
                    telerikControls:Theming.Theme="Office_Blue"
                    SelectedValue="{Binding TrusteeID, Mode=TwoWay}"
                    DisplayMemberPath="TrusteeCode" />
        </DataTemplate>

 

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
christine
Top achievements
Rank 1
Answers by
Maya
Telerik team
christine
Top achievements
Rank 1
Share this question
or