Ankush

Ankush

  • NA
  • 267
  • 63.2k

Get the value from datagrid to textbox using c#

Mar 24 2016 5:42 AM
I am developing a window application in which I have a datagridview. I get the data in datagridview from database and have added checkbox column in datagridview. when the checkbox is checked the value should be shown in label, for that I have written foreach loop and its working but,
when the user checks the first row the value is not refreshed, it gets refreshed when focus from first row is leaved.
 
Which is the appropriate datagridview event ??
 
The code  I have written
  1. Amt = 0;  
  2. foreach (DataGridViewRow dgr in dgvDetails.Rows)  
  3.    {  
  4.       if (Convert.ToBoolean(dgr.Cells[0].Value) == true)  
  5.       {  
  6.          Amt += Convert.ToInt32(dgr.Cells[12].Value.ToString());  
  7.       }  
  8.       txtCash_Amt.Text = Amt.ToString(); 
  9.    }   
 

Answers (4)