Setting ItemSource when RadCombo is in a GridView RowDetailsTemplate

9 posts, 0 answers
  1. Jared Smith
    Jared Smith avatar
    5 posts
    Member since:
    Mar 2004

    Posted 17 Mar 2010 Link to this post

    How do I reference and set the RadComboBox.ItemSource when it is inside a RadGridView RowDetailsTemplate.
  2. Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 19 Mar 2010 Link to this post

    Hi Jared,

    There are several ways to get ItemsSource:
    1) Reference your ViewModel, containing a collection property, that is present as static resource outside RadGridView:
    <UserControl.Resources>
    <local:ComboBoxItemsContainer x:Key="comboItems" />
    </UserControl.Resources>
    <telerikGridView:RadGridView>
    ...
    <DataTemplate>
        <telerikInput:RadComboBox ItemsSource="{Binding Items, Source={StaticResource comboItems}}" ... />
    </DataTemplate>
    ...
    </telerikGridView:RadGridView>

    2) Provide a property Items in the data objects, that will contain the items source (this would need modifications in your data objects), thus making it accessible in the DataTemplate's data context:
    <telerikGridView:RadGridView>
    ...
    <DataTemplate>
        <telerikInput:RadComboBox ItemsSource="{Binding Items}" ... />
    </DataTemplate>
    ...
    </telerikGridView:RadGridView>

    Sincerely yours,
    Valeri Hristov
    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. DevCraft banner
  4. Jared Smith
    Jared Smith avatar
    5 posts
    Member since:
    Mar 2004

    Posted 19 Mar 2010 Link to this post

    Thanks for the reply.  I guess I should be a bit more specific.
    I was trying to set the RadComboBox.ItemSource in Code Behind.  I've got a collection there that came from a Web Service.  When my RadComboBox isn't in a DataTemplate or RowDetailsTemplate I can just say RadComboBox.ItemSource = myCollection;

    Can you give me some sample C# code for referencing the RadComboBox and it's ItemSource (or any other properties) when it is in a RowDetailsTemplate?

    Thanks
  5. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 19 Mar 2010 Link to this post

    Hello Jared Smith,

    In order to access the combo box in a row details template you should subscribe to the LoadingRowDetails event of RadGridView and use the e.DetailsElement.FindName("TheNameOfMyComboBox"), where e is the event arguments passed to this event. Here is a sample code snippets that illustrates this:

    XAML
    <telerik:RadGridView
        x:Name="clubsGrid"
        LoadingRowDetails="clubsGrid_LoadingRowDetails"
        RowDetailsVisibilityMode="VisibleWhenSelected">
        <telerik:RadGridView.Columns>
            ...
        </telerik:RadGridView.Columns>
        <telerik:RadGridView.RowDetailsTemplate>
            <DataTemplate>
                <telerikInput:RadComboBox x:Name="DetailsComboBox" />
            </DataTemplate>
        </telerik:RadGridView.RowDetailsTemplate>
    </telerik:RadGridView>

    C#
    void clubsGrid_LoadingRowDetails(object sender, GridViewRowDetailsEventArgs e)
    {
        var combo = e.DetailsElement.FindName("DetailsComboBox") as RadComboBox;
         
        // assign combo.ItemsSource here
    }


    Hope this helps,
    Stefan Dobrev
    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.
  6. Jared Smith
    Jared Smith avatar
    5 posts
    Member since:
    Mar 2004

    Posted 23 Mar 2010 Link to this post

    Perfect!  That's exactly what I was looking for.  Thanks
  7. Jared Smith
    Jared Smith avatar
    5 posts
    Member since:
    Mar 2004

    Posted 23 Mar 2010 Link to this post

    One more extenstion question to this.

    I can see that accessing the RadComboBox by using e.DetailsElement.FindName works inside the LoadingRowDetails event.
    What about from inside other Events?  For instance.  I have 2 combo boxes on a RadGridView.DetailsTemplate. (Category and Subcategory).  I want to change the SubCategory.ItemSource in the Category_SelectionChanged event. 

    So based on the Category.SelectedValue I get the collection of SubCategory items and set the SubCategory.ItemSource.

    How would I access the SubCategory RadComboBox in the RadGridView.DetailsTemplate from within the Category_SelectionChanged event of another combobox that is also in the DetailsTemplate?

    I was trying to do something with ChildrenOfType<> or ParentOfType<>.  Or the RadGridView.ItemContainerGenerator.  But wasn't sure if that was the direction to go and couldn't figure it out.

    Your help and a little more direction would be greatly appreciated.
  8. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 26 Mar 2010 Link to this post

    Hi Jared Smith,

    The best way to approach this is to create a separate UserControl which contains those combos. In this UserControl you can implement whatever logic you want including your cascading combos scenario. Then the only this you have to do is place this UserControl in the RowDetailsTemplate.

    Hope this helps,
    Stefan Dobrev
    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.
  9. Tyson
    Tyson avatar
    9 posts
    Member since:
    Apr 2007

    Posted 07 Sep 2011 Link to this post

    Not sure if this helps anyone else with this question, but you can reference controls inside the RowDetailsTemplate from anywhere...

    RadGridView gridChild= ((Grid)list.gridParent.RowDetailsTemplate.LoadContent()).FindChildByType<RadGridView>();

    You just have to load the row details template.
  10. Moumita
    Moumita avatar
    2 posts
    Member since:
    Feb 2013

    Posted 12 Feb 2013 Link to this post

    How to implement the reverse concept.....
    When I Have a Parent RadGridView which has a ComboBox Column. And when this combobox will be opened another RadGridView will be visible there ??

    Due to performance issue I want to avoid RowDetailsTemplate concept
Back to Top
DevCraft banner