Quantcast
Viewing all articles
Browse latest Browse all 18858

Nested Datagrids

Hello,

 

I have a question about nesting two datagrids.

I have a main datagrid which is bound to a ObservableCollection of custom objects (classA) in my ViewModel.

This custom object has a couple of properties and 1 ObservableCollection of other custom objects (classB) .

I’m binding the properties to the columns of the main datagrid, this works fine. But binding the ObservableCollection of classB to the RowDetails section of the datagrid gives me some problems.

In my viewmodel I have:

public ObservableCollection<ClassA> CollectionClassA;

And for ClassA en ClassB:

public class ClassA

{

     string Property1;

     string Property2;

     ObservableCollection<ClassB> CollectionClassB;

}

public class ClassB

{

     string OrderRow;

     DateTime OrderDate;

}

My view:


<DataGrid x:Name="mainDataGrid" DataContext="{Binding CollectionClassA}" ItemsSource="{Binding}" Grid.Row="1"
                          SelectedItem="{Binding SelectedClassA_Object, Mode=OneWayToSource}" FontSize="13" AutoGenerateColumns="False" GridLinesVisibility="Vertical"
                          SelectionUnit="FullRow" SelectionMode="Single" RowDetailsVisibilityMode="Visible"
                          CanUserResizeColumns="False" CanUserResizeRows="False" IsEnabled="True" CanUserAddRows="False" AlternationCount="2"><!-- DataGrid Columns --><DataGrid.Columns><DataGridTextColumn Binding="{Binding Path=Property1}" 
                                    CellStyle="{StaticResource CenterCellStyle}"
                                    Header="Property 1:" Width="180" IsReadOnly="True" KeyboardNavigation.IsTabStop="False"/><DataGridTextColumn Binding="{Binding Path=Property2}" 
                                    CellStyle="{StaticResource CenterCellStyle}"
                                    Header="Property 2:" Width="360" IsReadOnly="True" KeyboardNavigation.IsTabStop="False"/></DataGrid.Columns><DataGrid.RowDetailsTemplate><DataTemplate ><Border Height="100" Width="1200" Grid.Row="1" BorderBrush="#FFA4ADBB" BorderThickness="1" CornerRadius="3,3,0,0" Margin="3" HorizontalAlignment="Left"><Grid><DataGrid ItemsSource="{Binding Path=CollectionClassB}"  
                                  CanUserAddRows="False"  Margin="5" HeadersVisibility="Column" Grid.Row="1" IsReadOnly="True"><DataGrid.Columns><DataGridTextColumn Binding="{Binding Path=OrderRow}"  Header="Order row:"/><DataGridTextColumn Binding="{Binding Path=OrderDate}" Header="Order date:"/></DataGrid.Columns></DataGrid></Grid></Border></DataTemplate></DataGrid.RowDetailsTemplate></DataGrid>

 

In every row there detail section, I want to show the collection of classB objects of that particular object, this needs to be visible all time ( so not be bound or dependant on the selecteditem in the main datagrid).

 

Any help would be greatly appreciated.

 

Marcel



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>