Hierarchical Data Grid (RadGridView). Select only one nested row at a time.

2 posts, 0 answers
  1. Top Gun
    Top Gun avatar
    20 posts
    Member since:
    Nov 2009

    Posted 03 Oct 2011 Link to this post

    I have a (Hierarchical) RadGridView that contains a list of people.  Each row has a person. 
    And each row can be expanded to show a list of classes for that person (in nested RadGridView).

    Everything works fine. However, the difficult part is making the user select ONLY one class (nested row) at a time.
    Right now, each row (person can be expanded) and a class can be selected for each person.  How can I restrict the user to only select one nested row at a time.
    I hope this makes sense.


    xaml

    <Controls:RadGridView x:Name="PeopleGrid"  Margin="0"
                                RowIndicatorVisibility="Collapsed" IsReadOnly="True" 
                                Width="748" MinHeight="386" MaxHeight="500"
                                AutoGenerateColumns="False"
                                VerticalAlignment="Top" 
                                VerticalContentAlignment="Stretch" 
                                HorizontalContentAlignment="Stretch"  
                                HorizontalAlignment="Stretch"
                                RowLoaded="PeopleGrid_RowLoaded" 
                                >
               <Controls:RadGridView.Columns>              
                   <Controls:GridViewDataColumn Header="ID" DataMemberBinding="{Binding ID}" />
                   <Controls:GridViewDataColumn Header="First Name" DataMemberBinding="{Binding FirstName}" />
                   <Controls:GridViewDataColumn Header="Last Name" DataMemberBinding="{Binding LastName}" />
               </Controls:RadGridView.Columns>
               <telerik:RadGridView.ChildTableDefinitions>
                   <telerik:GridViewTableDefinition>
                       <telerik:GridViewTableDefinition.Relation>
                           <telerik:PropertyRelation ParentPropertyName="ClassList"/>
                       </telerik:GridViewTableDefinition.Relation>
                   </telerik:GridViewTableDefinition>
               </telerik:RadGridView.ChildTableDefinitions>          
           </Controls:RadGridView>

    c#.net
    public MainPage()
           {
               InitializeComponent();
               DataContext = this;
               People = new ObservableCollection<Person>(GetPeople());
               EnterClasses();
               PeopleGrid.ItemsSource = People;
           }
           private ObservableCollection<Person> _people;
           public ObservableCollection<Person> People
           {
               get { return _people; }
               set { _people = value; }
           }
           private List<Person> GetPeople()
           {
               var returnPeople = new List<Person>
                                      {
                                          new Person() {ID = "1111", FirstName = "John", LastName = "Doe"},
                                          new Person() {ID = "2222", FirstName = "Mary", LastName = "Edwards"},
                                          new Person() {ID = "3333", FirstName = "Jane", LastName = "Doe"},
                                      };
               return returnPeople;
           }
           private void EnterClasses()
           {
               var c1 = new ClassSubject()
                           {Professor = "Dr. John Dyer", Subject = "Biology", Time = "3PM - 4:30PM", UniqueId = "53913"};
               var c2 = new ClassSubject() { Professor = "Dr. George Berry", Subject = "Math", Time = "1PM - 2:00PM", UniqueId = "52973" };
               var classSchedule = new List<ClassSubject>
                                       {
                                           new ClassSubject() {Professor = "Dr. John Dyer", Subject = "Biology", Time = "3PM - 4:30PM", UniqueId = "53913"},
                                           new ClassSubject() {Professor = "Dr. Ron Maher", Subject = "Physics", Time = "3PM - 4:30PM", UniqueId = "53913"},
                                           new ClassSubject() {Professor = "Dr. George Berry", Subject = "Math", Time = "1PM - 2:00PM", UniqueId = "52973"}
                                       };
               var p1 = People[0];
               p1.ClassList = new ObservableCollection<ClassSubject>(classSchedule);
               var p2 = People[2];
               p2.ClassList = new ObservableCollection<ClassSubject>(classSchedule);
           }
             
           private void PeopleGrid_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
           {
               GridViewRow row = e.Row as GridViewRow;
               if (row == null) {return;}
               Person oPerson = row.DataContext as Person;
               if (oPerson != null)
               {
                   row.IsExpandable = oPerson.IsExpandable;
               }
               else
               {
                   row.IsExpandable = false;
               }
           }
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Oct 2011 Link to this post

    Hi Amrit,

    Please take a look at this forum thread for a reference.
     

    Best wishes,
    Maya
    the Telerik team

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

Back to Top