Hi all!
I am very slowly building my first WPF application, so please be patient. I have been stuck with this one for a while now, so I hope someone here at CP can help me.
I have a data grid, when the user double clicks on it, i want to read a unique id that is stored in a column with a known index. Using this article:
http://www.scottlogic.co.uk/blog/colin/2008/12/wpf-datagrid-detecting-clicked-cell-and-row/[
^] I have written the following code, which works allright:
dep = DirectCast(e.OriginalSource, DependencyObject)
Do While Not dep Is Nothing
dep = VisualTreeHelper.GetParent(dep)
If TypeOf (dep) Is DataGridCell Then
Do While Not dep Is Nothing
dep = VisualTreeHelper.GetParent(dep)
If TypeOf (dep) Is DataGridCellsPanel Then
dgc = DirectCast(VisualTreeHelper.GetChild(dep, 1), DataGridCell)
lId = CLng(DirectCast(dgc.Content, TextBlock).Text.ToString)
MsgBox("id i'm looking for: " & lId.ToString)
Exit Do
End If
Loop
Exit Do
End If
Loop
Now, if the column containing the id is hidden, this code will not work... I understand that this is because I am using the Visual Tree... Should I use the logical tree instead? I have tried to, but the parent of the datagridcell is nothing.
So, any idea how to do this? I don't need code as much as an idea of what class should I use. C# code is welcome too.
TIA for your help