我正在嘗試將 DataGridView 初始化為 12 列 x 15 行(帶標簽),它們都是組合框。稍后在代碼中,我計劃用一個名為names(). 但我什至無法通過加載代碼。
另外,我有沒有機會獲得一個示例或一些關于以后如何將names()陣列添加到每個組合框的鉤子?我想按下一個運行正則運算式的按鈕來從陣列的文本檔案中提取值。
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.RowHeadersWidth = 50
Dim comboBoxCell As New DataGridViewComboBoxCell
For row As Integer = 0 To 14
Dim i As Integer = DataGridView1.Rows.Add()
DataGridView1.Rows(i).HeaderCell.Value = (i 1).ToString()
For col As Integer = 0 To 11
DataGridView1(col, row) = comboBoxCell
Next
Next
End Sub
Private Sub RefreshButton_Click(sender As Object, e As EventArgs) Handles RefreshButton.Click
'***** REGEX code to extract name values from text file add to array called names() *****
'***** some more code to enumerate DataGridView1 combo boxes with names() array *****
End Sub
uj5u.com熱心網友回復:
您真的應該閱讀有關如何使用 DataGridView 控制元件的資訊。
這是一個幫助您入門的解決方案,以便您可以處理資料加載:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.RowHeadersWidth = 50
'Initialise the grid rows and columns. Columns must be specified first.
'No need to add individually for initial state.
DataGridView1.ColumnCount = 12
DataGridView1.RowCount = 15
For row As Integer = 0 To 14
DataGridView1.Rows(row).HeaderCell.Value = (row 1).ToString()
For col As Integer = 0 To 11
'Each cell in the grid needs a new instance of combobox
DataGridView1(col, row) = New DataGridViewComboBoxCell
Next
Next
End Sub
Private Sub RefreshButton_Click(sender As Object, e As EventArgs) Handles RefreshButton.Click
'***** REGEX code to extract name values from text file add to array called names() *****
Dim names As String() = {"select", "one", "two", "three", "four", "five"}
'***** some more code to enumerate DataGridView1 combo boxes with names() array *****
Dim combo As DataGridViewComboBoxCell
For row = 0 To DataGridView1.Rows.Count - 1
For col = 0 To DataGridView1.Columns.Count - 1
combo = DataGridView1(col, row)
combo.DataSource = names
Next
Next
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/415373.html
標籤:
