始终在Datagridview中填充CheckboxColumn

时间:2016-04-15 06:51:54

标签: vb.net

我有2 Datagridview,那就是DataGridView1和2,第一个通过表单加载填充,第二个将根据Datagridview选中,

填充

这是我正在使用的代码:

Dim checkBoxColumn As New DataGridViewCheckBoxColumn()
        Dim i As Integer
        i = DataGridView1.CurrentRow.Index
        Dim con As MySqlConnection = New MySqlConnection("server=localhost;userid=root;password=admin1950;database=fulldatabase")
        Dim sql As MySqlCommand = New MySqlCommand("select SubControls from subpriv where mainformname = '" & DataGridView1.Item(0, i).Value & "';", con)
        Dim ds As DataSet = New DataSet
        Dim adapter As MySqlDataAdapter = New MySqlDataAdapter
        con.Open()
        adapter.SelectCommand = sql
        adapter.Fill(ds, "MyTable")
        DataGridView2.DataSource = ds.Tables(0)
        con.Close()
            checkBoxColumn.HeaderText = "Approve"
            checkBoxColumn.Width = 120
            checkBoxColumn.Name = "checkBoxColumn"
            DataGridView2.Columns.Insert(0, checkBoxColumn)

但我的问题是,每次我在DatagridView1中选择时,我的代码总是填充checkboxcolumn

我的问题是如何只能限制为1 Checkboxcolumn

1 个答案:

答案 0 :(得分:0)

我猜您使用CellContentClick事件,在这种情况下我会执行以下操作:

Private Sub dgvdatos_CellContentClick(sender As DataGridView, e As DataGridViewCellEventArgs) Handles dgvdatos.CellContentClick
    If TypeOf (sender.CurrentCell) Is DataGridViewCheckBoxCell And e.RowIndex = 0 Then
  'DO STUFF
End If End Sub