简体   繁体   English

如何使用VB.Net中的datagridview windowsform在我的复选框列中添加复选框

[英]How to add a checkbox in my checkbox column using datagridview windowsform in VB.Net

Private Sub Recipients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    mycom.Connection = cn
    mycom.CommandText = <SQL> SELECT Idno,Name,YearSec,Course,Organization FROM tbl_students </SQL>.Value

    Dim myadap As New MySqlDataAdapter(mycom)
    Dim mydt As New DataTable

    mydt.Columns.Add("", GetType(Boolean))
    myadap.Fill(mydt)
    grdRecipients.DataSource = mydt

    myadap.Dispose()

End Sub

I have a problem creating a checkbox in the header of my checkbox column, which will supposed to be a checkbox so that i can check all the rows which are present in the data gridview. 我在我的复选框列的标题中创建一个复选框时遇到问题,该复选框应该是复选框,以便我可以检查数据gridview中存在的所有行。 Any answer will greatly help. 任何答案都会有很大帮助。 thanks 谢谢

Try Like This 像这样尝试

    DataGridViewCheckBoxColumn c1;
    CheckBox ckBox;

   grdRecipients.DataSource = mydt

   ckBox = new CheckBox();

  //Get the column header cell bounds
  Rectangle rect =
  this.dataGridView1.GetCellDisplayRectangle(0, -1, true);
  ckBox.Size = new Size(18, 18);

  //Change the location of the CheckBox to make it stay on the header
  ckBox.Location = rect.Location;
  ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);

  //Add the CheckBox into the DataGridView
  this.dataGridView1.Controls.Add(ckBox);

Below method use to check uncheck all checkbox 下面的方法用于选中取消选中所有复选框

     void ckBox_CheckedChanged(object sender, EventArgs e)
    {
        for (int j = 0; j < this.dataGridView1.RowCount; j++)
        {
            this.dataGridView1[0, j].Value = this.ckBox.Checked;
        }
        this.dataGridView1.EndEdit();
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Windows窗体VB.net将复选框列添加到网格视图 - How to add checkbox column into grid view using Windows form VB.net VB.net BoundField到复选框 - VB.net BoundField To Checkbox Datagridview 总和列错误 / vb.net - Datagridview Sum Column Error / vb.net 循环复选框列并使用dgv数据运行sql代码,具体取决于检查状态VB.NET - Loop through checkbox column and run sql code with dgv data, dependent on check state, VB.NET vb.net中如何将datagridview的记录值列移动到另一个记录列,然后保存到数据库中 - how to move the datagridview record value column to another record column and then save it into the database in the vb.net VB.net-使Gridview复选框更新数据库中的布尔字段 - VB.net - make Gridview checkbox update boolean field in database 无法取消选中Grid View VB.NET中的复选框 - Can't uncheck checkbox in Grid View VB.NET vb.net我如何以编程方式从datagridview向sql数据库添加新行(和更新) - vb.net how do i add a new rows (and update) from datagridview programmatically to sql database 如何使用VB.Net检查列上的数据是否仍然存在 - How to check if Data on column still exist using VB.Net 如何使用数据适配器或vb.net中的其他方法通过datagridview将记录插入到sql中以进行更新 - how to update, insert records through datagridview to sql using data adapter or other method in vb.net
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM