[ASK] -CheckBox DataGridView [英] [ASK ]-CheckBox DataGridView

查看:54
本文介绍了[ASK] -CheckBox DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用DataGridView.我的问题是
1.如何检查是否已检查行.例如,我有5行,选中了第二行和第四行.我需要显示2和4(每个已检查行的索引).
2.上面有2个选中的行.如何计算它们?

通过dataTable和DataAdapter从sql Server数据库中检索数据,并在列集合属性"中手动添加checkBox列.
这是我的代码,无法正常运行

Hi, I''m working with DataGridView. My questions are;
1. How to check if the rows are checked. For example, I have 5 rows, 2nd row and 4th row are checked. What I need is showing 2 and 4 (the index of each checked rows).
2. Above, there are 2 checked rows. How to count them?

The data is retrieved from sql server database through dataTable and DataAdapter and the checkBox column is added manually in Column Collection Properties.
Here''s my code and it''s not working properly

private void setTidakAktifToolStripMenuItem_Click(object sender, EventArgs e)
{
    for (int i = 0; i < this.gridUser.Rows.Count -1; i++)
    {
        int c = 0;
        //if (Convert.ToBoolean(this.gridUser.Rows[i].Cells["ColCheckBox"].Value) == true) //not working
        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)this.gridUser.Rows[i].Cells["ColCheckBox"];
        if (Convert.ToBoolean(chk.Value) == true)
            c++;
    }
    //also not working
    //foreach (DataGridViewRow row in this.gridUser.Rows)
    //{
    //    if (Convert.ToBoolean(((DataGridViewCheckBoxCell)row.Cells["ColCheckBox"]).Value) == true)
    //        c++;
    //}
    //MessageBox.Show(c.ToString());
}

推荐答案

将dk chk作为新复选框

而< datagrid.rows.count>
chk = ctype(datagrid.rows(a).cell(1).controls [1],CheckBox)
如果chk.checked则
您的操作
如果
dim chk as new checkbox

while a<datagrid.rows.count>
chk=ctype(datagrid.rows(a).cell(1).controls[1],CheckBox)
if chk.checked then
your operation
end if


这篇关于[ASK] -CheckBox DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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