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

RadTabControl bound to data source - how to access RadTabItems?

5 Answers 129 Views
TabControl
This is a migrated thread and some comments may be shown as answers.
s2uiguy
Top achievements
Rank 1
s2uiguy asked on 28 Apr 2011, 10:40 PM
Hi,

So I have a RadTabControl that is bound to a data source and the names of the individual tab items are bound to the Name property within that data source.
In some code-behind I need to be able to loop through the RadTabItems that are dynamically created as a result of being bound to this data source so that I can attach a tooltip to each RadTabItem.

I'm having difficulty figuring out how to access these RadTabItems.

I tried something like the following

foreach(RadTabItem item in MyTabControl.items) 
{
...
}

but that is just returning the data source objects and not the actual RadTabItem.

Any idea on how to get a handle on the actual RadTabItems that have been created....

Thanks you for any help.

5 Answers, 1 is accepted

Sort by
0
Accepted
Petar Mladenov
Telerik team
answered on 03 May 2011, 01:15 PM
Hello fortpointuiguy,

You can use the RadTabControl.ItemContainerGenerator.ContainerFromItem(object item) method. But you have to ensure that the containers (the Radtabitems) are already been generated. It`s a bit tricky because the Loaded event of the RadtabControl may not be sufficient, probably a Dispatcher is needed in most cases like so:
private void tabControl_Loaded(object sender, RoutedEventArgs e)
       {
           Dispatcher.BeginInvoke(() =>
           ForeachAllTabItems());
       }
       private void ForeachAllTabItems()
       {
           foreach (var item in this.tabControl.Items)
           {
               RadTabItem tabItem = this.tabControl.ItemContainerGenerator.ContainerFromItem(item as DataItem) as RadTabItem;
               if (tabItem != null)
               {
               }
           }
       }
Please let us know if this satisfies you or not.

All the best,
Petar Mladenov
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
s2uiguy
Top achievements
Rank 1
answered on 03 May 2011, 04:26 PM
Hi Petar,

Thanks for the reply.  I completely understand your solution so that's good but I'm having trouble figuring out where DataItem is defined (i.e. what assembly).

In the line
...ItemContainerGenerator.ContainerFromItem(item as DataItem)

What is a DataItem and in what assembly does that exist?

I apologize as this is probably a basic question and I've tried navigation the class documentation but had difficulty tracking down DataItem.

Any additional help would be appreciated.

0
s2uiguy
Top achievements
Rank 1
answered on 03 May 2011, 04:37 PM
Petar - I change DataItem to just be Object and I was able to access the RadTabItems.

Could you please explain the DataItems when you get a chance though.

Thanks!
0
Petar Mladenov
Telerik team
answered on 03 May 2011, 04:43 PM
Hello fortpointuiguy,

"DataItem" was the name of my business objects that I used to populate the RadTabControl. It is not part of framework or something. Just a class that I have defined. Please let me know if you need more info.

Regards,
Petar Mladenov
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
s2uiguy
Top achievements
Rank 1
answered on 03 May 2011, 04:48 PM
That makes total sense  - thanks.
Tags
TabControl
Asked by
s2uiguy
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
s2uiguy
Top achievements
Rank 1
Share this question
or