带CheckBox列的DataGridView。如果通过单击选中包含Row,我想在CheckBox列中选中CheckBox。 [英] DataGridView with CheckBox Column. I want to make the CheckBox selected in the CheckBox Column if the containing Row is selected by clicking on it.

查看:93
本文介绍了带CheckBox列的DataGridView。如果通过单击选中包含Row,我想在CheckBox列中选中CheckBox。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们。我有一个 DataGridView 控件,其中包含 CheckBoxColumn ,并且Header上有 CheckBox 。有一些关于这个主题的文章,但是,我希望DataGridView的行为就像我在主题中说的那样,当你选择电子邮件的复选框并且相应的行也被选中时,就像yahoo或gmail一样。是否有人有关于此的一些线索?



提前致谢!!!

Hi fellows. I have a DataGridView control with a CheckBoxColumn in it, and a CheckBox on the Header. There are some articles regarding this topic , but, i want the DataGridView to behave like i said in the Subject, like yahoo or gmail when you select the checkbox of an email and the corresponding row gets selected too.Does anyone have some clues regarding this?

Thanks in advance!!!

推荐答案

你可以在下面的表单加载事件中使用

U can use below on form load event
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
chk.HeaderText = "Check Data";
chk.Name = "chk";
dataGridView1.Columns.Add(chk);



然后更改coor on复选框点击放置代码 cellmouseclick


then on to change coor on checkbox click put code on cellmouseclick.

if (dataGridView1.Rows[e.RowIndex].Cells["chk"].Value == true)
{
       for(int i=0;i < dataGridView1.Rows[e.RowIndex].Cells.Count; i++)
       {
            dataGridView1.Rows[e.RowIndex].Cells[i].Style.BackColor = Color.Green;
       }
}



希望它能帮到你。


hope it helps u out.


这篇关于带CheckBox列的DataGridView。如果通过单击选中包含Row,我想在CheckBox列中选中CheckBox。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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