2015-05-21 102 views
0
  • 我有DataGridView名爲「DataGridView1」。
  • 在DataGridView中,有兩列名爲「Process」,另一列名爲「Size」。
  • 大小列是一個組合框。
  • 當我點擊一個按鈕來創建一個進程時,它必須在Process列中輸入 中的「1」,並獲取用戶輸入的大小,並放入 「Chart1」(條形圖類型)。 - 我想獲取大小並存儲在一個名爲「UsedMemory」的變量中並放在圖表上。如何從Datagridview Combobox中獲取值?

    Me.DataGridView1.Rows.Add("1") 'Add 1 to the first column (idk if it's right). 
    
    For i = 0 To 25 Step 1 'populate the Combo with 25 items. 
        Me.Tamanho.Items.Add(i) 
    Next 
    
    UsedMemory = 'I need the ComboValue here As Integer... and I don't know if I need to set up a default value. 
    
    Me.Chart1.Series("Memory").Points.AddXY("Memory", UsedMemory) 
    

回答

1

只是爲了可讀性,這將是最好的(但不是必要的)首先填充組合框。然後,要檢索該值,只需按照您通常對任何其他列類型執行操作即可。

For i = 0 To 25 Step 1 'populate the Combo with 25 items. 
    Me.Tamanho.Items.Add(i) 
Next 

Me.DataGridView1.Rows.Add("1", 1) 'the second parameter is the default value the combobox column will have 

UsedMemory = Me.DataGridView1.Rows(0).Cells(1).Value '0 or any index you need 

Me.Chart1.Series("Memory").Points.AddXY("Memory", UsedMemory) 
+0

非常感謝Josh!這對我幫助很大! –