Click here to Skip to main content
15,909,242 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
note it is windows application.

i have one datagridview, in that datagridview i have two checkboxes.

Two checkbox name as follows;

First checkbox column name checkboxselect
Header text Day

Second checkbox column name sess1
Header text session


inside the datagridview the above two check boxes will be there.

i want when i click the first checkbox checked, i want second checkbox to checked in datagridview
similarily when i clcik the second checkbox to unchecked first checkbox to be uncheckedin datagridview.

for that i written a code in datagridview CellValueChanged.

my code as follows;


private void DGVCalendar_CellValueChanged(object sender, DataGridViewCellEventArgs e)

{

if(DGVCalendar.Columns[e.ColumnIndex].Name == "checkboxselect" && DGVCalendar.CurrentCell is DataGridViewCheckBoxColumn)
bool ischecked = (bool)DGVCalendar[e.ColumnIndex,e.RowIndex].EditedFormattedValue;
if(ischecked == true)
{
DGVCalendar.Columns[3].Name = false;
}
}


from my code checkboxselect is the firstcheckbox and i mention the column(3) is the second checkbox.

i written a above code when i click the first checkbox i want second checkbox to unchecked.

for that how to do?

from my code what is the mistake i made

when i run the above code error as follows;
Embedded statement cannot be a declaration or labeled statement

please help me
regards,
Narasiman p.

note it is windows application.
Posted

1 solution

private void DGVCalendar_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            try
            {
 

                DataGridView dgv = (DataGridView)sender;
                DataGridViewCell cell = dgv.CurrentCell;
                if (cell.RowIndex > -1 && (cell.ColumnIndex == 1 || cell.ColumnIndex == 2))
                {
                    if (cell.ColumnIndex == 1)
                    {
                        DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = true;
                        DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = false;
                    }
                    else
                    {
                        DGVCalendar.Rows[cell.RowIndex].Cells[2].Value = true;
                        DGVCalendar.Rows[cell.RowIndex].Cells[1].Value = false;                    
                    }                    
                }
            }
            catch (Exception exc)
            {
 
                exc.ToString();
            }
        }
 
Share this answer
 

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