【问题标题】:checkbox selection and removing columns in datagridview复选框选择和删除datagridview中的列
【发布时间】:2015-04-03 01:30:16
【问题描述】:

我的 DataGridView 不能正常工作。这是我的代码,我只想显示 4 列,第一列是复选框列。

        Dim dt_zone As DataTable
        Dim iCounter As Integer

        dt_zone = obj_aims_zone.get_row_for_display("", area_id)
        dvg_selected_group_list.DataSource = Nothing
        If dt_zone IsNot Nothing Then
            If dt_zone.Rows.Count > 0 Then
                dvg_selected_group_list.DataSource = dt_zone
                For Each row As DataGridViewRow In dvg_selected_group_list.Rows
                    If row.Cells(3).Value.ToString.Equals(group_id) Then
                        row.Cells(check.Index).Value = True
                    End If
                    row.Cells(1).ReadOnly = True
                    row.Cells(2).ReadOnly = True
                    row.Cells(3).ReadOnly = True
                    row.Cells(4).ReadOnly = True
                Next
                For iCounter = 1 To 7
                    dvg_selected_group_list.Columns.RemoveAt(5)
                Next
            End If
        End If

【问题讨论】:

  • 您遇到的具体问题是什么?
  • 您能谈谈 dt_zone 数据源吗?您显示的代码看起来应该可以执行您想要的操作,尽管这不是我编写的方式。
  • 我的问题是复选框没有选中,我删除的列没有被删除,在 datagridview 中,显示 dt_zone 中的全部数据,我只想显示 4 列,每个列都有复选框
  • 我的 dt_zone 有 11 列,我想显示 dt_zone 表的前四列,每列带有复选框,复选框值取决于 dt_zone 列第 3 值。
  • 我把 dvg_selected_group_list.DataSource = dt_zone 放到 form_load() 和其余的编码(添加复选框值 true,删除列)到 button_click() ,它工作正常。但是把这两件事放在一起并不合适

标签: vb.net datagridview checkbox


【解决方案1】:

我知道这是不久前的事情,但删除不需要的列似乎更容易:

dataGridView.Columns.Remove("column name")

【讨论】:

    猜你喜欢
    • 2011-02-17
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多