RAK
RAK

Reputation: 283

How to bind a RadGridView in RowDetailsTemplate of another RadGridView

A RadGridView is bound to a List (e.g., Samples). In RowDetailsTemplate I want to show another RadGridView that will show the related records from another List (e.g., Analysis).

The main RadGridView is bound at Code behind as:

GrdSamples.ItemsSource=SamplesViewModel.GetAll();

How can I bind the RadGridView in RowDetailsTemplate (GrdAnalysis) in the same way? And on which event I will get the key ID, So that I can use Something like:

var SampleID = ? 
GrdAnalysis.ItemsSource=AnalysisViewModel.Get(SampleID);

Here is the XAML,

 <telerik:RadGridView x:Name="GrdSamples" AutoGenerateColumns="False">
      <telerik:RadGridView.Columns>...</telerik:RadGridView.Columns>
         <telerik:RadGridView.RowDetailsTemplate>
          <DataTemplate>
               <telerik:RadGridView x:Name="GrdAnalysis" 
                AutoGenerateColumns="False">
          </DataTemplate>
      </telerik:RadGridView.RowDetailsTemplate> 
     </telerik:RadGridView>

Upvotes: 0

Views: 348

Answers (1)

mm8
mm8

Reputation: 169420

You could handle the Loaded event:

private void OnLoaded(object sender, RoutedEventArgs e)
{
    RadGridView inner = (RadGridView)sender;
    var sample = inner.DataContext as Sample;
    if (sample != null)
    {
        var SampleID = sample.Id;
        inner.ItemsSource = AnalysisViewModel.Get(SampleID);
    }
}

XAML:

<DataTemplate>
    <telerik:RadGridView x:Name="GrdAnalysis" Loaded="OnLoaded" AutoGenerateColumns="False">
</DataTemplate>

Sample is the type of objects returned by the SamplesViewModel.GetAll() method in the above sample code.

Upvotes: 1

Related Questions