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

[Solved] Binding data into RadGridView in tabControl

1 Answer 163 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Cheng Lim Sek
Top achievements
Rank 1
Cheng Lim Sek asked on 01 Dec 2009, 10:20 AM

Hi,

I have some problems for binding the List<> into my a radgridview in tabcontrol.

I have a list of person. List<List<Person>>

I have already successful binding the person information to RadGridViewPerson.
this.RadGridViewPerson.ItemsSource = personList;

In the personList, it has AddressList also. List<List<Address>>

I do not want to bind all data into all the GridView for performance issue.
Instead, I hope the Address list will populate when some event occur for example, RowDetailVisibilityChanged.
Any suggestion or idea to my situation?

 

 

1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 03 Dec 2009, 04:51 PM
Hi Cheng Lim Sek,

You should remove the Address column and show addresses by using the Row Details feature. Row Details have lazy loading built in. This means that unless you click on a row to show its row details, they will never be loaded thus the data will not be populated.

Alternatively, if you think that data will / may change between two consecutive openings of a specific row details, you can leave the control in your RowDetailsTemplate unbound and attach to the RowDetailsVisibilityChanged event of the grid.

When the event occurs and (e.Visibility == Visible) (row details are showing) you can manually populate the address list and give it as a source to whatever control you have inside the row details. You can see the master record from the e.Row.DataContext property. Cast e.DetailsElement to the type of control you have placed inside the RowDetailsTemplate and populate it with data.

I have attached a sample project that does this. You can use my sample project as a base. Here is the important stuff:

using System;
using System.Windows.Controls;
using Telerik.Windows.Controls;
using Telerik.Windows.Data;
using SelectionMode=System.Windows.Controls.SelectionMode;
 
namespace TicketID_255822_RowDetailsGridDynamicItemsSource
{
    public partial class MainPage : UserControl
    {
        readonly Random random = new Random();
         
        public MainPage()
        {
            InitializeComponent();
 
            this.clubsGrid.ItemsSource = Club.GetClubs();
            this.clubsGrid.SelectionMode = SelectionMode.Multiple;
        }
 
        void OnClubsGridRowDetailsVisibilityChanged(object sender, Telerik.Windows.Controls.GridView.GridViewRowDetailsEventArgs e)
        {
            if (e.Visibility == System.Windows.Visibility.Visible)
            {
                // You can safely cast e.DetailsElement to whatever you have put in the RowDetailsTemplate.
                DetailsGridControl dgc = (DetailsGridControl)e.DetailsElement;
                 
                // Remember that the DataContext of the DetailsElement is always the DataContext of the
                // GridViewRow it belongs to, in our case a football club. You can use it if you need it
                // when retrieving dynamic data.
                Club club = (Club)dgc.DataContext;
 
                // I made some dummy dynamic data:
                // Have in mind that the RadGridView
                dgc.Players.Clear();
                dgc.Players.Add(new Player(string.Format("{0} Player {1}", club.Name, random.Next(0, 100)), random.Next(0, 11), Position.MF, "Some Country"));
                dgc.Players.Add(new Player(string.Format("{0} Player {1}", club.Name, random.Next(0, 100)), random.Next(0, 11), Position.MF, "Some Country"));
                dgc.Players.Add(new Player(string.Format("{0} Player {1}", club.Name, random.Next(0, 100)), random.Next(0, 11), Position.MF, "Some Country"));
 
                // Another approach would be to locate the child grid by using
                // the ChildrenOfType method and the simply work on its
                // ItemsSource, but it is not reccomended.
 
                // RadGridView playersGrid = dgc.ChildrenOfType<RadGridView>()[0];
                // playersGrid.ItemsSource = ...
            }
        }
    }
}

Here are the resources you will need to consult in order to implement this:

Row Details Help Topic
Row Details Online Example
How To: Display Hierarchical Data with Row Details (RadGridView for Silverlight)

I hope this helps.

Kind regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Cheng Lim Sek
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or