2016-01-29 44 views
1

這應該是一個快速的。Can .net組合框直接指向一個對象?

我想知道如果.net組合框可以指向一個對象的實例。

目前我填充組合框與此:

Private Sub validation_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

     paramPairComboBox.ValueMember = "uniqueName" 
     paramPairComboBox.DisplayMember = "name" 
     paramPairComboBox.DataSource = payload.parameterPairs 

End Sub ''validation_Load() 

正如你所看到的,我必須使用一個字符串,它是專用於特定對象的ValueMember。

什麼是真正竊聽我的是,我必須這樣做:

Private Sub paramPairComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles paramPairComboBox.SelectedIndexChanged 

     Dim graphBuilder As GraphBuilder 
     Dim indexSearch As IndexFinder = New IndexFinder(paramPairComboBox.SelectedValue) 
     Dim pairIndex As Integer = payload.parameterPairs.FindIndex(AddressOf indexSearch.find) 
     indexSearch = Nothing 
     System.Diagnostics.Debug.Write(pairIndex) 

     Dim param1 As String = payload.parameterPairs(pairIndex).param1 
     Dim param2 As String = payload.parameterPairs(pairIndex).param2 

     graphBuilder = New GraphBuilder(payload.testData.table, payload.parameterPairs(pairIndex)) 

     engineChart.Series.Clear() 

     engineChart.Series.Add(graphBuilder.getSeries()) 
     engineChart.ResetAutoValues() 
    End Sub ''paramPairComboBox_SelectedIndexChanged 
End Class 

''' <summary> 
''' Class to provide search functionality 
''' </summary> 
Class IndexFinder 

    Dim _s As String 

    Public Sub New(s As String) 
     _s = s 
    End Sub 

    ''' <summary> 
    ''' The search function 
    ''' </summary> 
    ''' <param name="pair"></param> 
    ''' <returns></returns> 
    Public Function find(pair As LimitParameterPair) As Boolean 
     Return pair.uniqueName.Contains(_s) 
    End Function ''find() 

End Class 

綜上所述代碼,我要創建一個類看過那部功能有助於尋找對象的列表裏面是唯一的字符串。我覺得很麻煩。

所以基本上,有沒有什麼辦法來完成這樣的事情:

Private Sub validation_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

     paramPairComboBox.ValueMember = Me (or) This (or something??) 
     paramPairComboBox.DisplayMember = "name" 
     paramPairComboBox.DataSource = payload.parameterPairs 

    End Sub ''validation_Load() 
+0

引用對象的實例「有效載荷」是什麼樣的對象,似乎是一個相當複雜的方式來找到相關項目 – Plutonix

+0

我真的很抱歉,但我不能讓你說的正面或反面... –

+0

你使用'payload.parameterPairs'作爲數據源 - 它是什麼?數據表,列表,別的東西? – Plutonix

回答

0

似乎答案就在我的鼻子。默認情況下,組合框將指向所選擇的對象不是通過SelectedValue而是SelectedItem

所以,我的代碼就變成了:

Private Sub validation_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

     paramPairComboBox.DataSource = payload.parameterPairs 
     paramPairComboBox.DisplayMember = "name" 

    End Sub ''validation_Load() 

然後我就可以簡單地通過使用paramPairComboBox.SelectedItem

+0

...那也:)我沒有注意到, – Plutonix

+0

:)感謝您的所有輸入,雖然! –

相關問題