Click here to Skip to main content
15,997,553 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
when i click the radio button in datagridview all check box value to be checked true.

My code as follows in radio button checked_changed_Event;

private void SessAM_CheckedChanged(object sender, EventArgs e)
      {
            if (SessAM.Checked = true)
          {
              for (int i = 0; i < DGv_Session.RowCount; i++)
              {

                  DGv_Session.Rows[i].Cells[1].Value = true;
                  DGv_Session.Rows[i].Cells[2].Value = true;
                  i++;
              }
          }

      }

Ouptut as follows in datagridview;

RadioButton

Days 1 2

1 chbox chbox
2 chbox chbox
3 chbox chbox
4 chbox chbox
5 chbox chbox

When i click the radio button, in datagridview Days 1,3 and 5 chbox value only checked.

Reamining 2 and 4 checkbox value is unchecked why?

when i click the radio button i want all the Days 1 to 5 all checkbox to be checked.
Posted
Updated 11-Mar-13 0:11am
v3

1 solution

C#
for (int i = 0; i < DGv_Session.RowCount; i++)
{
    DGv_Session.Rows[i].Cells[1].Value = true;
    DGv_Session.Rows[i].Cells[2].Value = true;
    i++;
}

You are incrementing your index twice, once in the for statement and once in the loop body.
 
Share this answer
 
Comments
[no name] 11-Mar-13 6:27am    
for (int i = 0; i < DGv_Session.RowCount; i++)
{
DGv_Session.Rows[i].Cells[1].Value = true;
DGv_Session.Rows[i].Cells[2].Value = true;
i++;
}

i tried your abvoe code but is not working.

in the days 1,3 and 5 only checked.

Reamining 2 and 4 in datagridview rows are not checked?

why?


Please help me.
Richard MacCutchan 11-Mar-13 6:30am    
Because, as I said above, you are incrementing the index twice, and thus skipping the even numbered rows. Remove the i++ statement at the bottom of the loop.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900