Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

I am developing windows application using C#.net...In that I have one datagridview with 3 DataGridViewCheckBoxColumn (checkbox1,checkbox2,checkbox3)..

here i want to uncheck the remainining 2 colums while i checked one particular column..for eg,1st i check checkbox1 and i change to check checkbox2,that time i need to uncheck checkbox1 column automatically and viceversa........

Help me out guys!!!!!!!!!
Posted

do it in CheckedChanged event of clicked control, you can also get current row of the clicked control, and also you can find the remaining controls from the same row.
 
Share this answer
 
Comments
Nathansathya 22-Aug-11 8:34am    
Hi Anil,

There is no CheckedChanged event occur for datagridview...How can i create it?
am developing Windows application....
Finally i got solution for this....

write following code on CellValidating event,

C#
int column = e.ColumnIndex;
            int row = e.RowIndex;
            if (column == 2)
            {
                DataGridViewCheckBoxCell c = dgv1[e.ColumnIndex, e.RowIndex] as DataGridViewCheckBoxCell;
                if (c != null)
                {
                    string a = e.FormattedValue.ToString();
                    if (a == "True")
                    {                       
                        dgv1.Rows[row].Cells["column2"].Value = false;
                        dgv1.Rows[row].Cells["column3"].Value = false;
                    }
                    else
                    {                        
                        dgv1.Rows[row].Cells["column1"].Value = false;
                        dgv1.Rows[row].Cells["column2"].Value = false;
                        dgv1.Rows[row].Cells["column3"].Value = false;
                    }
                }
            }


repeat the code for remaining columns........
 
Share this answer
 
DataTable dt = new DataTable()
foreach (DataRow row in dt.Rows)
{
if (row["gridviewcheckboxcolumnname"].ToString() == "True")
{
//your Code
}
}
 
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