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

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

1 Answer 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Top Gun
Top achievements
Rank 1
Top Gun asked on 03 Oct 2011, 10:08 PM

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;
           }
       }

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 04 Oct 2011, 09:25 AM
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 >>

Tags
GridView
Asked by
Top Gun
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or