当使用csharp时,单击datagridview复选框中的单选按钮是真的 [英] when radio button click in datagridview checkbox is to be true using csharp

查看:100
本文介绍了当使用csharp时,单击datagridview复选框中的单选按钮是真的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试过但它不能正常工作,我的代码如下;



i有一个单选按钮,当我点击单选按钮时,在datagridview checkbox1和checkbox2检查确实。



我的代码如下;





in the从加载我想要一个条件,当我运行radiobutton是在表单加载时取消选中,

当用户点击单选按钮时复选框和复选框2在datagridview中得到true。



代码如下,我试过但它不起作用。





i tried but it is not working, my code as follows;

i have one radio button, when i click the radio button, in the datagridview checkbox1 and checkbox2 checked true.

My Code as follows;


in the from load i want one condition, when i run radiobutton is to unchecked in the form load,
when user click the radiobutton bothe the checkbox1 and checkbox2 gets true in the datagridview.

code as follows, i tried but it is not working.


private void cb_am_CheckedChanged(object sender, EventArgs e)
{

        if(cb_am.Checked = true)
    {
        dataGridView1.Rows[0].Cells[0].Value = true;
        dataGridView1.Rows[0].Cells[1].Value = true;
    }

}





我上面代码中的错误是什么?



请帮帮我。



问候,

Narasiman。



注意它是windows应用程序。



what is the mistake in my above code?

Please help me.

Regards,
Narasiman.

Note it is windows application.

推荐答案

你的错误是你没有考虑到第二个取消选中复选框的可能性。

您的代码是:

Your mistake is that you didn't take into account the 2nd possibility which is unchecking the checkboxes.
You code is:
if(cb_am.Checked = true)
          {
              dataGridView1.Rows[0].Cells[0].Value = true;
              dataGridView1.Rows[0].Cells[1].Value = true;
          }



你需要添加以下几行:


and you need to add the following lines:

else
{
    dataGridView1.Rows[0].Cells[0].Value = false;
    dataGridView1.Rows[0].Cells[1].Value = false;
}


你的第一个错误是你正在使用



Your first mistake is that you are using

if(cb_am.Checked = true)





应该是





which should be

if(cb_am.Checked == true)





你的第二个错误是你没有考虑第二种可能性,即取消选中复选框。

你的代码是:



Your 2nd mistake is that you didn't take into account the 2nd possibility which is un-checking the checkboxes.
You code is:

if(cb_am.Checked == true)
          {
              dataGridView1.Rows[0].Cells[0].Value = true;
              dataGridView1.Rows[0].Cells[1].Value = true;
          }



你需要添加以下几行:


and you need to add the following lines:

else
{
    dataGridView1.Rows[0].Cells[0].Value = false;
    dataGridView1.Rows[0].Cells[1].Value = false;
}


hi,

首先在代码中,您不需要专门检查对于控件的状态,当你分配正确或错误时,它可以很简单:


First of all in code, you do not need to exclusively check for the state of the control, when you are assigning just true or false, it could be as simple as:
private void cb_am_CheckedChanged(object sender, EventArgs e)
{
    dataGridView1.Rows[0].Cells[0].Value = cb_am.Checked;
    dataGridView1.Rows[0].Cells[1].Value = cb_am.Checked;
}





您基本上将单选按钮的状态分配给单元格中的复选框。



其次,单选按钮不像复选框,要更改一个单选按钮的状态,另一个单选按钮必须是Checked = true;,所以你需要至少两个收音机按钮来检查和取消选中这些单元格中的复选框。



第三,你只是在cb_am控件的CheckChanged事件中设置复选框的状态,有些此控件可能不会改变其状态,例如,如果您有三个单选按钮,cb_am,cb_am1和cb_am2,如果单选按钮的状态从cb_am1更改为cb_am2,则cb_am不会触发CheckChanged事件,因此复选框在那些单元格不会更新。



我希望这会有所帮助。



问候

Jegan



you are basically assigning the state of the radio button to the checkbox in the cell.

Second, radio button are not like check boxes, to change the state of one radio button, an another radio button must be "Checked = true;", so you need at least two radio buttons to check and uncheck your check boxes in those cells.

Third, you are only setting the state of the check boxes in the CheckChanged event of the cb_am control, some times this control may not change its state, such as if you have three radio buttons, cb_am, cb_am1 and cb_am2, if the state of the radio button changes from cb_am1 to cb_am2, the cb_am will not trigger the CheckChanged event, so the checkboxes in those cells will not be updated.

I hope this helps.

Regards
Jegan


这篇关于当使用csharp时,单击datagridview复选框中的单选按钮是真的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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