views:

76

answers:

3

How when I click my datagridview command is run?

          Int64 sum = 0;
        foreach (DataGridViewRow dr in dg_Cheque.Rows)
        {
            if (Convert.ToBoolean(dr.Cells["True_False"].Value) == true) //Cells[0] Because in cell 0th cell we have added checkbox
            {
                sum +=Convert.ToInt64(dr.Cells[0].Value.ToString());
            }
        }

        label1.Text = sum.ToString();

In any event I write it?

A: 

There is a MouseClick event

Itay
This event was not the answer
textBox
+1  A: 

It depends where you click on the DataGridView. If you want to run this command when you double click a cell within the grid you could use the CellContentDoubleClick event.

The full list of events for a DataGridView can be found here

EDIT:

It appears that you want to capture a click event for a CheckBox within the DataGrid?

In order to capture the Checkbox changed event you can subscribe to the OnCellValueChanged event. Within the EventArgs check to see what column has been changed. If it is your checkbox column then you can run you command.

Something along these lines of this (untested):

private void DataGridView1_OnCellValueChanged(object sender, DataGridViewCellEventArgs e)
{

   if (e.ColumnIndex == 0 && e.RowIndex > -1) // Replace 0 with the checkbox col index
   {
         if ((bool)this.DataGridView1[e.ColumnIndex, e.RowIndex].Value == true)
         {
             // Checkbox is checked so call you command
         }
   }

}
Barry
This event was not the answer
textBox
@textBox - I have updated my answer
Barry
A: 

All events do not respond

This column is a checkedbox

I must click twice to give the answer that first click

textBox