I have a sfdatagrid and have the following code to get a cell value. Unfortunately, this code returns an empty string if the row hasn't yet been saved to the datasource (an observable collection). I trap for a right mouse click and then want to get the value of the clicked cell and open a dialog based on the cell value. How can I get the value of a cell if the data hasn't been saved to the datasource?
Private Function GetCellValue(ByVal RowNum As Integer, ByVal ColumnNum As Integer) As String
Dim CellString As String = String.Empty
Dim MappingName As String
Dim RecordIndex As Integer
Dim Record As NodeEntry
Dim RecordOb As Object
Dim Data As Object
Dim CellValue As Object
If ColumnNum < 0 Then
Return String.Empty
End If
MappingName = gridReceipts.Columns(ColumnNum).MappingName
RecordIndex = gridReceipts.TableControl.ResolveToRecordIndex(RowNum)
If recordIndex < 0 Then
Return String.Empty
End If
If gridReceipts.View.TopLevelGroup IsNot Nothing Then
Record = gridReceipts.View.TopLevelGroup.DisplayElements(RecordIndex)
If Not record.IsRecords Then
Return String.Empty
End If
Data = (TryCast(Record, RecordEntry)).Data
CellString = (Data.GetType().GetProperty(MappingName).GetValue(Data, Nothing).ToString())
Else
RecordOb = gridReceipts.View.Records.GetItemAt(RecordIndex)
CellValue = RecordOb.GetType().GetProperty(MappingName).GetValue(RecordOb, Nothing)
If CellValue IsNot Nothing Then
CellString = CellValue.ToString()
End If
End If
Return cellstring
End Function