Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Datagridview checkbox.checked event
 

Datagridview checkbox.checked event

I have a checkbox column and a amount column in my datagridview.Now when i check one of the checkboxes i want to display the total of that row.How can one capture that checked event.
jedC_nerd  Monday, July 07, 2008 11:37 AM
You can subscribe the CurrentCellDirtyStateChanged event of the datagrid and start the recalculation there:

dataGridView1.CurrentCellDirtyStateChanged += OnCurrentCellDirtyStateChanged;

void OnCurrentCellDirtyStateChanged( object sender, EventArgs e )
{
if ( CurrentCell.Index == xyz)
RecalculateAmount();
}

or you can try the EditingControlShowing event and check what kind of editing control you get there. If I remember correctly, a recent post stated, that the CheckBoxCell doen't use a common CheckBox control. So you have to check what's possible there.

--
Wolfgang

Wollinet  Monday, July 07, 2008 12:41 PM
You can subscribe the CurrentCellDirtyStateChanged event of the datagrid and start the recalculation there:

dataGridView1.CurrentCellDirtyStateChanged += OnCurrentCellDirtyStateChanged;

void OnCurrentCellDirtyStateChanged( object sender, EventArgs e )
{
if ( CurrentCell.Index == xyz)
RecalculateAmount();
}

or you can try the EditingControlShowing event and check what kind of editing control you get there. If I remember correctly, a recent post stated, that the CheckBoxCell doen't use a common CheckBox control. So you have to check what's possible there.

--
Wolfgang

Wollinet  Monday, July 07, 2008 12:41 PM
Thanks i have done it this way.

private void getDebOutInvBalDataGridView_CellValueChanged(object sender, DataGridViewCellEventArgs e)

{

try

{

if ((bool)this.getDebOutInvBalDataGridView[e.ColumnIndex, e.RowIndex].Value == true)

{

totalAmount = totalAmount - float.Parse(getDebOutInvBalDataGridView.Rows[getDebOutInvBalDataGridView.CurrentCell.RowIndex].Cells["dataGridViewTextBoxColumn3"].Value.ToString());

tbTotal.Text = totalAmount.ToString();

}

else if ((bool)this.getDebOutInvBalDataGridView[e.ColumnIndex, e.RowIndex].Value == false)

{

totalAmount = totalAmount + float.Parse(getDebOutInvBalDataGridView.Rows[getDebOutInvBalDataGridView.CurrentCell.RowIndex].Cells["dataGridViewTextBoxColumn3"].Value.ToString());

tbTotal.Text = totalAmount.ToString();

}

}

catch { };

}

private void getDebOutInvBalDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{

getDebOutInvBalDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);

}


jedC_nerd  Monday, July 07, 2008 1:43 PM
private void getDebOutInvBalDataGridView_CurrentCellDirtyStateChanged(object sender, EventArgs e)

{

getDebOutInvBalDataGridView.CommitEdit(DataGridViewDataErrorContexts.Commit);

}



Your solution was useful to me, but can u please describe this part ?


Afshin_Zavar  Thursday, March 12, 2009 9:40 PM

You can use google to search for other answers

Custom Search

More Threads

• DataGridViewCheckBoxColumn Check Changed
• Scroll DataGridView while dragging cell over frozen column
• datagrid size
• DtatGridView.RowValidating Event and changing is BindingSource's List
• Re: Retreive Data from Datatable
• datagrid synchronization
• Row disappearance in DGVs
• simple data binding to text control
• Databind one control to another
• DataGridView Focusing a particular row