Windows Develop Bookmark and Share   
 index > Windows Forms General > how to generate event while check a checkbox inside a datagrid view in c#
 

how to generate event while check a checkbox inside a datagrid view in c#

how to generate event while check a checkbox inside a datagrid view in c#..if i use cell content click or cell mouse click..it will not work....
help me asap..

if i click checkbox inside a datagrid view...


i have to enable or disable the buttons below the datagridview in c# Windows Application
How can i do?

the code is like below.

private void dataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
j = 0;
for (int intLp = 0; intLp <= dataGridView1.Rows.Count - 1; intLp++)
{

DataGridViewCheckBoxCell chkactive = (DataGridViewCheckBoxCell)dataGridView1.Rows[intLp].Cells[0];




if (chkactive.Value != null)
{
if (chkactive.Value.ToString() == "TRUE")
{
j = j + 1;
}
//if (j > 1)
//{
// btnmodify.Enabled = false;
// btndelete.Enabled = true;
// btnadd.Enabled = false;

//}
//else if (j == 1)
//{
// btnmodify.Enabled = true;
// btndelete.Enabled = false;
// btnadd.Enabled = false;
//}
//else if (j == 0)
//{
// btnmodify.Enabled = false;
// btndelete.Enabled = false;
// btnadd.Enabled = true;

//}
}
else
{
}

}




if (j > 1)
{
btnmodify.Enabled = false;
btndelete.Enabled = true;
btnadd.Enabled = false;

}
else if (j == 1)
{
btnmodify.Enabled = true;
btndelete.Enabled = false;
btnadd.Enabled = false;
}
else if (j == 0)
{
btnmodify.Enabled = false;
btndelete.Enabled = false;
btnadd.Enabled = true;

}


}

Reply me asap..
kumarvelayutham  Saturday, September 19, 2009 11:38 AM

Hi,

You can use the CurrentCellDirtyStateChanged event to get the checkboxcell value.

Usually, if you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. So we need to use another way to catch the changed value. A common method is handling CurrentCellDirtyStataChanged event to commit the changes.

Please refer to the remarks part of DataGridViewCheckBoxColumn Class.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx

MSDN document shows an example about how to commit the changes in DataGridView.CurrentCellDirtyStateChanged Event.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx

DataGridView does not have built-in support for disabling a cell. You can change surface. One FAQ tells about this.

15. How do I disable a cell?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq15

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Saturday, September 26, 2009 4:44 PM

Hi,

You can use the CurrentCellDirtyStateChanged event to get the checkboxcell value.

Usually, if you want to respond immediately when users click a check box cell, you can handle the DataGridView.CellContentClick event, but this event occurs before the cell value is updated. So we need to use another way to catch the changed value. A common method is handling CurrentCellDirtyStataChanged event to commit the changes.

Please refer to the remarks part of DataGridViewCheckBoxColumn Class.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcheckboxcolumn.aspx

MSDN document shows an example about how to commit the changes in DataGridView.CurrentCellDirtyStateChanged Event.

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.currentcelldirtystatechanged.aspx

DataGridView does not have built-in support for disabling a cell. You can change surface. One FAQ tells about this.

15. How do I disable a cell?

http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/a44622c0-74e1-463b-97b9-27b87513747e#faq15

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Ling Wang  Saturday, September 26, 2009 4:44 PM

You can use google to search for other answers

Custom Search

More Threads

• create columnFilter dynamically using propertyInfo?
• using another form
• How can i show report in vb.net
• statistisk counter application.
• Use mouse up instead of mouse down
• Where is the Focus Leaving to?
• going from one windows form to another
• Question about copy data from multiple array to one-dimension array, e.g. htt = (Int32[]) tt.getValue(1);
• Control portrait/landscape page orientation?
• General question: how do we search on the various dotnet languages here?