Hi,
I have one Grid with columns Id,Name,Balance.Here is my DatagGridView.Where Cr. and Dr. are Credit and Debit.
Id Name Balance
1 Sai 10000Cr.
2 Ram 3000Dr.
3 Anu 5000Cr.
4 Swathi 4000Dr.
And I have a TextBox outside of GridView,I want to do sum operation on the above 4 values and the result(8000Cr) should be stored in TextBox.Here I didn't use CheckBox and which DataGridView click event we will write the code?
Thanks in advance.
Loading

Rahul PrajapatPosted Aug 17, 2015, 8:37 AM
{
int Amount = 0;
foreach (DataGridViewRow gr in dataGridView1.Rows)
{
string str = gr.Cells[2].Value.ToString();
if (str.Contains("Dr."))
Amount -= int.Parse(str.Substring(0, str.Length - 3));
else
Amount += int.Parse(str.Substring(0, str.Length - 3));
}
if (Amount > 0)
textBox1.Text = Amount.ToString() + " Cr";
else
{
Amount = Amount * -1;
textBox1.Text = Amount.ToString() + "Dr";
}
}
Kanaparthi Sureshma ReddyPosted Aug 18, 2015, 2:20 AM