RadTabControl bound to data source - how to access RadTabItems?

6 posts, 1 answers
  1. s2uiguy
    s2uiguy avatar
    24 posts
    Member since:
    Jan 2011

    Posted 28 Apr 2011 Link to this post

    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.
  2. Answer
    Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 May 2011 Link to this post

    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
  3. DevCraft banner
  4. s2uiguy
    s2uiguy avatar
    24 posts
    Member since:
    Jan 2011

    Posted 03 May 2011 Link to this post

    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.

  5. s2uiguy
    s2uiguy avatar
    24 posts
    Member since:
    Jan 2011

    Posted 03 May 2011 Link to this post

    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!
  6. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 03 May 2011 Link to this post

    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
  7. s2uiguy
    s2uiguy avatar
    24 posts
    Member since:
    Jan 2011

    Posted 03 May 2011 Link to this post

    That makes total sense  - thanks.
Back to Top
DevCraft banner