WPF application using DataGrid. User double-clicks on a cell, and I need to get the value of another cell in that row.
Dim dep As DependencyObject = DirectCast(e.OriginalSource, DependencyObject)
Dim dgRow As DataGridRow = Nothing
While dep IsNot Nothing
If TypeOf dep Is DataGridRow Then
dgRow = DirectCast(dep, DataGridRow)
End If
dep = VisualTreeHelper.GetParent(dep)
End While
So now, I have the row, I want to get the value from a specific column:
Dim xx As String = dgRow.Item("xx")
This gets me "Option Strict On disallows late binding" with no correction options. It works fine with Option Strict Off. I have tried all the following to correct it:
dgRow.Item("xx").ToString
DirectCast(dgRow.Item("xx"), String)
CType(dgRow.Item("xx"), String)
However, the red-squiggly line remains under dgRow.Item("xx") in all these scenarios.
Appreciate any input, including alternate ways to go about this.
UPDATE
Here's the code that ultimately worked. I looked at the type for the Item property and it was DataRowView. Thanks to Mark's answer below.
dgRow = DirectCast(DirectCast(dep, DataGridRow).Item, DataRowView)
This allowed me to do this without the late binding error:
dgRow.Item("xx").ToString