-1

我正在使用 ArcGIS。我试图在找到数据后手动对数据进行排序。我创建了一个属性类并循环遍历一个 Tlist 以清理不需要的数据。然而,在它绑定到数据网格之前,我收到了一个转换错误。我认为有些东西会返回空值。我错过了什么吗?

 Public Class temp
    Public Sub New()
    End Sub
    Public Property DisplayFieldName As String
    Public Property Feature As ESRI.ArcGIS.Client.Graphic
    Public Property FoundFieldName As String
    Public Property LayerId As Integer
    Public Property LayerName As String
    Public Property Value As Object
End Class

Public Class templst
    Public Sub New()
        Dim findresult = New List(Of temp)
    End Sub
    Private _findresult = findresult
    Public Property findresult() As List(Of temp)
        Get
            Return _findresult
        End Get
        Set(ByVal value As List(Of temp))
            _findresult = value
        End Set
    End Property
End Class

Private Sub FindTask_Complete(ByVal sender As Object, ByVal args As FindEventArgs) 
        Dim newargs As New templst() 'puts Tlist (temp) into property
        Dim templistNUMONLY As New List(Of temp) 'Tlist of temp
            For Each r In args.FindResults 'class in compiled dll.
                 If Regex.Match(r.Value.ToString, "[0-9]").Success Then
                templistNUMONLY.Add(New temp() With {.LayerId = r.LayerId,
                                              .LayerName = r.LayerName,
                                              .Value = r.Value,
                                              .FoundFieldName = r.FoundFieldName,
                                              .DisplayFieldName = r.DisplayFieldName,
                                              .Feature = r.Feature})
                 End If
            Next

        newargs.findresult = templistNUMONLY

            Dim sortableView As New PagedCollectionView(newargs.findresult)
            FindDetailsDataGrid.ItemsSource = sortableView 'populate lists here
        End Sub

在此处绑定到网格:(此处错误)

Private Sub FindDetails_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs)
        ' Highlight the graphic feature associated with the selected row
          Dim dataGrid As DataGrid = TryCast(sender, DataGrid)

          Dim selectedIndex As Integer = dataGrid.SelectedIndex
           If selectedIndex > -1 Then
          '''''''''''''''''CAST ERROR HERE:
           Dim findResult As FindResult = CType(FindDetailsDataGrid.SelectedItem, FindResult)
4

1 回答 1

1

您填充FindDetailsDataGrid了 type 的对象temp,但您尝试将其强制转换为 type FindResult。你应该做:

Dim selectedTemp As temp = CType(FindDetailsDataGrid.SelectedItem, temp)
'*Create find result from selected temp object here*
于 2012-12-03T17:49:50.530 回答