How to insert RadGrid inside RadTabItem

9 posts, 1 answers
  1. Yana
    Yana avatar
    32 posts
    Member since:
    Aug 2011

    Posted 17 Aug 2011 Link to this post

    Hi guys, 

    Can you please help me on how to insert RadGrid and RadButton inside a RadTabItem of the RadControl?
    Pretty please. Thanks.


    Y
  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 23 Aug 2011 Link to this post

    Hello Yana,

    You can populate the RadTabControl with Items declaratively in XAML like so:
    <telerik:RadTabControl>
        <telerik:RadTabItem Header="GridView">
            <telerik:RadGridView />
        </telerik:RadTabItem>
        <telerik:RadTabItem Header="Button">
            <telerik:RadButton Content="RadButton" />
        </telerik:RadTabItem>
        <telerik:RadTabItem Header="Controls">
            <StackPanel>
                <telerik:RadGridView />
                <telerik:RadButton Content="RadButton1" />
            </StackPanel>
        </telerik:RadTabItem>
        <telerik:RadTabItem Header="Quote" Content="Quote Text" />
    </telerik:RadTabControl>
    Or you can bind the ItemsSource collection of the control to a collection of business items and use the RadTabControl ItemTemplate and ContentTemplate properties to define what should be displayed as the Header and Content of the RadTabItems (read more). In this case you can define the RadGridView and the RadButtons in the ContentTemplate DataTemplate and bind their properties to the business items.

    I hope this information will help you get started on your task.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  3. UI for WPF is Visual Studio 2017 Ready
  4. Yana
    Yana avatar
    32 posts
    Member since:
    Aug 2011

    Posted 23 Aug 2011 Link to this post

    Can you please attach a simple example? Thanks!
  5. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 26 Aug 2011 Link to this post

    Hi Yana,

    I attached a sample project how to implement this scenario with databinding in this forum thread. This is why I attached to this thread a sample illustrating how to define the described layout declarative in xaml. I hope this will help you. Please let us know if we can further assist you.

    All the best,
    Tina Stancheva
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

  6. Yana
    Yana avatar
    32 posts
    Member since:
    Aug 2011

    Posted 01 Sep 2011 Link to this post

    Thanks so much! Just what I needed. 

    Cheers!

    Y
  7. Marian
    Marian avatar
    16 posts
    Member since:
    Dec 2010

    Posted 09 May 2012 Link to this post

    Hello,

    I have a problem with RadGridView inside RadTabItem - and in your example (WpfApplication3.zip) is the same problem. RadGridView on 3rd RadTabItem has no items before you select it.

    Try to change your code:
    public MainWindow()
    {
        InitializeComponent();
        this.radGridView1.ItemsSource = GenerateProducts();
        this.radGridView2.ItemsSource = GenerateProducts();
        MessageBox.Show(radGridView1.Items.Count.ToString());
        MessageBox.Show(radGridView2.Items.Count.ToString());
    }

    radGridView1 on 1st RadTabItem has 19 items, but radGridView2 on 3rd RadTabItem has 0 items. In my project I have same problem with version 2011.3.1220.35 and 2012.1.0326.35 too. In previous version used in my project (2010.3.1110.35) it works fine.

    Can you help me, please?


    Thanks,
    Maros

  8. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 14 May 2012 Link to this post

    Hi Maros,

    This behavior is expected because when the RadTabControl is loaded, it adds the content of its tabs in the logical tree of the application, but it doesn't add the controls in the visual tree. The content of a TabItem is added in the visual tree of the application only after the TabItem is selected. And the RadGridView Items collection is generated only when the control is added to the visual tree of the application.

    I hope that information will help you.

    Greetings,

    Tina Stancheva
    the Telerik team

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

  9. Richard
    Richard avatar
    2 posts
    Member since:
    Mar 2011

    Posted 07 Jun 2012 Link to this post

    Hi,

    I have a similar problem to Maros. I would like to force the RadTabControl to add the tab contents to the visual tree immediately and not wait for the TabItem to be selected. I'm happy to extend the RadTabControl class if that is necessary. I've seen that a few people have extended the standard WPF TabControl to work this way so it must be possible. I just need some direction on extending the control.

    Regards
    Andy
  10. Hristo
    Admin
    Hristo avatar
    352 posts

    Posted 12 Jun 2012 Link to this post

    Hello,

    There are several properties that are internal or private to the control that you could not access from the derived class. Also the code forcing visual controls realization may not be very pretty or straight forward.

    The more easy and straight forward way would be to select all tab items consequently one by one.

    Personally I would prefer to work with my view models when possible and not deal with visuals that are not yet visible. Forcing visuals to be created in advance and be invisible could harm performance and cause unexpected results.

    Greetings,
    Hristo
    the Telerik team

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

Back to Top
UI for WPF is Visual Studio 2017 Ready