I have a datagrid nested within a datagrid. The nested datagrid is only visible when a toggle button is pressed in the original datagrid.
This works fine, however i would like to be able to hide some of the columns in the nested datagrid.
I am using MVVM.
I have tried achieving this by binding the Visibility property of the Column to a visibility property in my view model, i also tried biding the width to an integer property in my viewmodel with no luck.
I have tried achiving this through the code behind, however i cant access the nested datagrid - it doesnt seem to be in the VisualTree at all.
The code i tried is :
Private Sub DgRowLoading(sender As Object, e As DataGridRowEventArgs) Handles OriginalDataGridName.LoadingRow
Dim test As DataGrid = OriginalDataGridName.FindName("NestedDataGridName")
I have even tried looping through the visual tree of the Original datagrid after the nested datagrid is loaded but the nested datagrid isn't found. The code i used is:
Private Sub LoopThroughControls(parent As UIElement)
Dim count As Integer = VisualTreeHelper.GetChildrenCount(parent)
If count > 0 Then
For i As Integer = 0 To count - 1
Dim child As UIElement = DirectCast(VisualTreeHelper.GetChild(parent, i), UIElement)
Dim childTypeName As String = child.[GetType]().ToString()
I have achieved similar thing just few days back but I was not having nested data grid. I was working on single data grid and this question helped me to complete my task.