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

Setting ItemSource when RadCombo is in a GridView RowDetailsTemplate

8 Answers 257 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jared Smith
Top achievements
Rank 1
Jared Smith asked on 18 Mar 2010, 04:39 AM
How do I reference and set the RadComboBox.ItemSource when it is inside a RadGridView RowDetailsTemplate.

8 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 19 Mar 2010, 10:32 AM
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.
0
Jared Smith
Top achievements
Rank 1
answered on 19 Mar 2010, 04:36 PM
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
0
Stefan Dobrev
Telerik team
answered on 19 Mar 2010, 06:06 PM
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.
0
Jared Smith
Top achievements
Rank 1
answered on 24 Mar 2010, 12:07 AM
Perfect!  That's exactly what I was looking for.  Thanks
0
Jared Smith
Top achievements
Rank 1
answered on 24 Mar 2010, 02:55 AM
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.
0
Stefan Dobrev
Telerik team
answered on 26 Mar 2010, 09:35 AM
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.
0
Tyson
Top achievements
Rank 1
answered on 07 Sep 2011, 04:13 PM
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.
0
Moumita
Top achievements
Rank 1
answered on 13 Feb 2013, 05:41 AM
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
Tags
ComboBox
Asked by
Jared Smith
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Jared Smith
Top achievements
Rank 1
Stefan Dobrev
Telerik team
Tyson
Top achievements
Rank 1
Moumita
Top achievements
Rank 1
Share this question
or