【问题标题】:VB.NET Click a checkbox into DatagridviewVB.NET 单击复选框进入 Datagridview
【发布时间】:2016-02-24 00:38:24
【问题描述】:

我有一个 DatagridView,其中的数据直接来自记录集。

我在其他列之前有一个新列作为带有此代码的复选框类型:

Dim chk As New DataGridViewCheckBoxColumn()
gridRicette.Columns.Add(chk)
chk.HeaderText = "Sel."
chk.Name = "chk"

它出现了。但是当我点击复选框时,什么也没有发生。

你能帮我解决吗?

谢谢!

【问题讨论】:

  • 您需要将其绑定到数据源上的正确列。见msdn.microsoft.com/en-us/library/…
  • 我做到了,但是当我点击复选框时,我没有“启用”选中/取消选中它...

标签: vb.net checkbox datagridview


【解决方案1】:

试试这样的......

Public Class Form1

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim chk As New DataGridViewCheckBoxColumn()
    gridRicette.Columns.Add(chk)
    chk.HeaderText = "Sel."
    chk.Name = "chk"
End Sub

Private Sub gridRicette_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles gridRicette.CellContentClick
    Dim senderGrid As DataGridView = sender
    Dim data = senderGrid.Rows(e.RowIndex).DataBoundItem

    If senderGrid.Columns(e.ColumnIndex).GetType() Is GetType(DataGridViewCheckBoxColumn) And e.RowIndex >= 0 Then
        MessageBox.Show(String.Format("You selected row {0}", e.RowIndex))
    End If
End Sub
End Class

您可以使用 DataGridView1_CellContentClick 事件,然后确定用户点击了什么......希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    相关资源
    最近更新 更多