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")
End Sub
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()
LoopThroughControls(child)
Next
End If
End Sub