搜索 Header 行并转到找到的特定列
Search Header Row and Go To The Specific Column That's Found
因此以下代码获取 header 行并填充组合框中的每个字段。
然后我想 select 组合框中的字段名称并转到数据网格视图中的该列,这可能吗?
Dim c As Integer
For cn = 0 To DataGridView1.Columns.Count - 1
c = c + cn
'Debug.Print(cn)
'Debug.Print(DataGridView1.Columns(cn).Name)
ComboBox1.Items.Add(DataGridView1.Columns(cn).Name)
Next cn
您想检查 DGV 是否有数据,也许还有 CurrentRow
:
Private Sub ComboBox1_SelectedIndexChanged(sender As Object,
e As EventArgs) Handles ComboBox1.SelectedIndexChanged
' ToDo: check that the selectedIndex is valid vs dgv.Columns.Count
If dgv1.CurrentRow IsNot Nothing Then
dgv1.CurrentCell = dgv1.CurrentRow.Cells(ComboBox1.SelectedIndex)
Else
dgv1.CurrentCell = dgv1.Rows(0).Cells(ComboBox1.SelectedIndex)
End If
End Sub
因此以下代码获取 header 行并填充组合框中的每个字段。
然后我想 select 组合框中的字段名称并转到数据网格视图中的该列,这可能吗?
Dim c As Integer
For cn = 0 To DataGridView1.Columns.Count - 1
c = c + cn
'Debug.Print(cn)
'Debug.Print(DataGridView1.Columns(cn).Name)
ComboBox1.Items.Add(DataGridView1.Columns(cn).Name)
Next cn
您想检查 DGV 是否有数据,也许还有 CurrentRow
:
Private Sub ComboBox1_SelectedIndexChanged(sender As Object,
e As EventArgs) Handles ComboBox1.SelectedIndexChanged
' ToDo: check that the selectedIndex is valid vs dgv.Columns.Count
If dgv1.CurrentRow IsNot Nothing Then
dgv1.CurrentCell = dgv1.CurrentRow.Cells(ComboBox1.SelectedIndex)
Else
dgv1.CurrentCell = dgv1.Rows(0).Cells(ComboBox1.SelectedIndex)
End If
End Sub