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

Nested Gridview Binding to LoadingRowDetails causing exception

0 Answers 138 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dave
Top achievements
Rank 1
Dave asked on 03 Dec 2012, 05:40 PM
Hi,

I've recently begun working on my first WPF application using Telerik's RadControls and I've run into a problem which I am unable to solve. I have a main RadGridView which has multiple levels of nested RadGridViews (3 nested gridviews in total). Each nested GridView relies on information from the parent in order to populate the columns and I do so by binding a method to the LoadingRowDetails event and pass that information to my ViewModel. When the nested gridview attempts to load the ObservableCollection, its Get method uses the retrieved information in order to execute an SQL query on the DB and populate the collection. 

My problem is that for some reason when I attempt to bind a method to the 3rd nested RadGridView, instead of working as the parents do, it throws an NullReferenceException (it doesn't even reach the method) upon attempting to expand just the first row.
I've read and searched everywhere for a solution, but to no avail.

I unfortunately cannot share my actual code, since my company prohibits it, but I hope this example is clear enough to perhaps allow for a solution.

<Grid>   
    <telerik:RadGridView x:Name="Tools" Marin="0" LoadingRowDetails="ToolsLoadingRowDetails" ItemsSource="{Binding Tools}" IsReadOnly="True" RowHeight="45" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" ShowGroupPanel="False">
        <telerik:RadGridView.Columns>
            <telerik:GridViewToggleRowDetailsColumn />
            <telerik:GridViewDataColumn Header="Product Id" DataMemberBinding="{Binding Path=TypeOfTool}" Width="*"/>
            <telerik:GridViewDataColumn Header="Target market" DataMemberBinding="{Binding Path=TargetMarket}" Width="3*"/>
           </telerik:RadGridView.Columns>
           <telerik:RadGridView:RowDetailsTemplate>
               <DataTemplate>
                   <telerik:RadGridView  Marin="0" LoadingRowDetails="MoreInfoLoadingRowDetails" ItemsSource="{Binding Path=DataContext.MoreInfo, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}}}" IsReadOnly="True" RowHeight="45" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" ShowGroupPanel="False">
                       <telerik:RadGridView.Columns>
                           <telerik:GridViewToggleRowDetailsColumn />
                           <telerik:GridViewDataColumn Header="More Info" DataMemberBinding="{Binding Path=MoreInfo}" Width="*"/>
                       </telerik:RadGridView.Columns>
                          <DataTemplate>
                               <telerik:RadGridView Marin="0" LoadingRowDetails="DetailedInfoLoadingRowDetails" ItemsSource="{Binding Path=DataContext.DetailedInfo, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}, AncestorLevel=2}}" IsReadOnly="True" RowHeight="45" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" ShowGroupPanel="False">
                                   <telerik:RadGridView.Columns>
                                       <telerik:GridViewToggleRowDetailsColumn />
                                      <telerik:GridViewDataColumn Header="Detailed Info" DataMemberBinding="{Binding Path=DetailedInfo}" Width="*"/>
                                   </telerik:RadGridView.Columns>
                                       <DataTemplate>
                                           <telerik:RadGridView Marin="0" LoadingRowDetails="TargetInfoLoadingRowDetails" ItemsSource="{Binding Path=DataContext.TargetInfo, RelativeSource={RelativeSource AncestorType={x:Type telerik:RadGridView}, AncestorLevel=3}}" IsReadOnly="True" RowHeight="45" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False" CanUserFreezeColumns="False" CanUserResizeColumns="True" ShowGroupPanel="False">
                                               <telerik:RadGridView.Columns>
                                                  <telerik:GridViewToggleRowDetailsColumn />
                                                  <telerik:GridViewDataColumn Header="Target Info" DataMemberBinding="{Binding Path=TargetInfo}" Width="*"/>
                                   </telerik:RadGridView.Columns>
                               </telerik:RadGridView>
                           </telerik:RadGridView.RowDetailsTemplate>
                       </telerik:RadGridView>
                   </DataTemplate>
               </telerik:RadGridView.RowDetailsTemplate>
           </telerik:RadGridView>
       </DataTemplate>
   </telerik:RadGridView.RowDetailsTemplate>
</telerik:RadGridView>

Again, I just wrote this by hand so it probably contains open/close tagging errors, but the overall idea should be understood.
The problematic event to bind to is the deepest one, in the example it is the "TargetInfo" GridView. 
The XAML works as long as I don't bind to the LoadingRowDetails event. The moment I add the binding, the code throws the NullReferenceException
open attempt to expand the first row.

I hope I've provided enough information regarding the problem.

Thanks

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Dave
Top achievements
Rank 1
Share this question
or