Hi all,
I hope your all alright. I am designing a cash denomination calculator and below is the code I have used.
private void dataGridView1_CellValidated_1(object sender, DataGridViewCellEventArgs e)
{
DataGridViewRow row = dataGridView1.Rows[e.RowIndex]
int a = System.Convert.ToInt32(row.Cells[ColumnA.Index].Value);
int b = System.Convert.ToInt32(row.Cells[ColumnB.Index].Value);
int c = (a * b);
row.Cells[ColumnC.Index].Value = c.ToString("n0");
dataGridView1.Columns["ColumnB"].Width = 170;
dataGridView1.Columns["ColumnC"].Width = 200;
}
However I have failed to find a way of getting the sum of the values for all rows of column, Is there a way I can get the sum of all rows of a column of a datagridview and display it in a textbox.text or a label.text
Loading

VulpesPosted Oct 7, 2011, 10:51 AM
This line:
should be:
Apologies for that :(
Marvin kakuruPosted Oct 7, 2011, 11:59 AM
Marvin kakuruPosted Oct 7, 2011, 10:46 AM
'System.Data.DataRow' does not contain a definition for 'IsNewRow' and no extension method 'IsNewRow'
'System.Data.DataRow' does not contain a definition for 'Cells' and no extension method 'Cells'
VulpesPosted Oct 7, 2011, 10:22 AM
Marvin kakuruPosted Oct 7, 2011, 10:03 AM
this code has worked though for the sum of all cells in the row.
sorry i asked a confusing question
VulpesPosted Oct 7, 2011, 6:30 AM
int total = 0;
int val = 0;
foreach(DataRow row in dataGridView1.Rows)
{
if (row.IsNewRow) continue;
int.TryParse(row.Cells[ColumnC.Index].Value.ToString().Replace(",", ""), out val);
total += val;
}
textBox1.Text = total.ToString("n0");