如何在 DataGridView 下拉菜单中制作 headers,并根据值填充列

How to make headers in a DataGridView drop downs, and populate the column based on the value

我是 VB 的新手,正在努力弄清楚如何进行这项工作。我在后端使用了 3 个数据库,这些数据库由表单填充。我想为用户创建生成自定义报告并将它们导出到 .csv 文件的能力。

我想在组合框中提供大约 20 个值的选项,而且我找不到比为所有 20 行手动输入每个值更好的方法来添加这些值(会非常长 public 子)哈哈。下面的代码有效,但无法扩展。除了 IF 语句之外,我还可以使用什么来使在 cmbColumn1 中选择的值确定如何从数据库填充该列?

Public Sub btnViewReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnViewReport.Click
    Dim OleDBC As New OleDbCommand
    Dim OleDBDR As OleDbDataReader
    Dim c As Integer
    c = 0
    If cmbColumn1.Text = "Patient ID" Then

        With OleDBC
            .Connection = conn
            .CommandText = "SELECT * FROM tblPatientsRecord WHERE PatientID like '%" & txtSearch.Text & "%'"
        End With
        OleDBDR = OleDBC.ExecuteReader
        DataGridViewReport.Rows.Clear()
        If OleDBDR.HasRows Then
            While OleDBDR.Read
                DataGridViewReport.Rows.Add()
                DataGridViewReport.Item(0, c).Value = OleDBDR.Item(0)

                c = c + 1
            End While
        Else
        End If
    End If
End Sub    
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        Dim comboBoxHeaderCell1 As ComboBox = New ComboBox()
        comboBoxHeaderCell1.DropDownStyle = ComboBoxStyle.DropDownList
        comboBoxHeaderCell1.Visible = True
        comboBoxHeaderCell1.Items.Add("Column1")
        comboBoxHeaderCell1.Items.Add("Column2")
        dataGridView1.Controls.Add(comboBoxHeaderCell1)
        comboBoxHeaderCell1.Location = Me.dataGridView1.GetCellDisplayRectangle(0, -1, True).Location
        comboBoxHeaderCell1.Size = Me.dataGridView1.Columns(0).HeaderCell.Size
        comboBoxHeaderCell1.Text = "Column1"
    End Sub