我創建了一個窗體具有以下控件:
ComboBox1
ComboBox2
Button1
TextBox1
我已經添加代碼到Form_Load和的button1_Click事件,並創造了單ComboBox_SelectedIndexChanged事件處理程序來處理這兩個組合框指數的變化。
Public Class Form1
Private _array(,) As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ReDim _array(0 To ComboBox1.Items.Count, 0 To ComboBox2.Items.Count)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim c1 As Integer = If(ComboBox1.SelectedIndex = -1, 0, ComboBox1.SelectedIndex)
Dim c2 As Integer = If(ComboBox2.SelectedIndex = -1, 0, ComboBox2.SelectedIndex)
Debug.Print(String.Format("Set ({0},{1}) to {2}", c1, c2, TextBox1.Text))
_array(c1, c2) = TextBox1.Text
End Sub
Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged
Dim c1 As Integer = If(ComboBox1.SelectedIndex = -1, 0, ComboBox1.SelectedIndex)
Dim c2 As Integer = If(ComboBox2.SelectedIndex = -1, 0, ComboBox2.SelectedIndex)
Debug.Print(String.Format("Get ({0},{1}) to {2}", c1, c2, TextBox1.Text))
TextBox1.Text = _array(c1, c2)
End Sub
End Class
什麼我展示的是:當加載窗體以匹配您的組合框元素的數量
1陣列調整。
2.將數據加載到數組中的事件(在本例中爲按鈕單擊事件)。
3.當任一組合框改變時再次檢索數據。
希望有所幫助。
那麼,這是如何爲你工作的? –