2012-12-03 19 views
-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 

BIND電網的位置:(錯誤這裏)

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) 
+0

那麼問題是什麼? –

+0

我問爲什麼會出現鑄造問題?我將如何解決這個問題。 – user999690

回答

1

您填充FindDetailsDataGridtemp類型的對象,但你嘗試將它轉換爲類型FindResult代替。你應該這樣做:

Dim selectedTemp As temp = CType(FindDetailsDataGrid.SelectedItem, temp) 
'*Create find result from selected temp object here* 
+0

工作!非常感謝你。我欠你很多時間! – user999690