通过一个DataGridView编程循环和检查复选框 [英] Programatically loop through a DatagridView and check checkboxes

查看:229
本文介绍了通过一个DataGridView编程循环和检查复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个DataTable我有复选框同样我也DataGridView的约束。



我要浏览或通过DataGridView中环和查马克这些复选框,下面是语法我使用。

 的foreach(在dgvColumns.Rows的DataGridViewRow DR)
{
DataGridViewCheckBoxCell checkCell =
(DataGridViewCheckBoxCell)dr.Cells [的CheckBox];
checkCell.Value = 1;
//也试过checkCell.Selected = TRUE;
//一切似乎已经奏效!
}


解决方案

下面为我工作,其检查的复选框完美:)

 的foreach(的DataGridViewRow行dgvDataGridView.Rows)
{
( (DataGridViewCheckBoxCell)row.Cells [0])值=真。
}


I have DataGridView bound by a datatable i have checkboxes to the same.

I want to navigate or loop through the the datagridview and check mark these checkboxes ,Below is the syntax i use .

foreach(DataGridViewRow dr in dgvColumns.Rows)
{
    DataGridViewCheckBoxCell checkCell =
        (DataGridViewCheckBoxCell)dr.Cells["CheckBoxes"];
    checkCell.Value=1;
    //Also tried checkCell.Selected=true;
    //Nothing seems to have worked.!
}

解决方案

The following worked for me, it checked the checkboxes perfectly :)

foreach (DataGridViewRow row in dgvDataGridView.Rows)
{
    ((DataGridViewCheckBoxCell)row.Cells[0]).Value = true;
}

这篇关于通过一个DataGridView编程循环和检查复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆