
14/08/2013, 15:16
|
 | | | Fecha de Ingreso: junio-2011
Mensajes: 200
Antigüedad: 13 años, 10 meses Puntos: 17 | |
Respuesta: Obtener promedio desde un DataGridView C# double suma = 0;
double promedio;
int contador = 0;
int indice = 2;
int filas = 0;
foreach (DataGridViewRow row in dgvTabla.Rows)
{
if (filas < dgvTabla.Rows.Count-1)
{
foreach (DataGridViewColumn col in dgvTabla.Columns)
{
if (row.Cells[indice].Value != DBNull.Value)
{
if (row.Cells[indice].Value != String.Empty)
{
contador++;
suma = suma + Convert.ToDouble(row.Cells[indice].Value);
}
}
if (indice < dgvTabla.Columns.Count - 1)
indice++;
}
promedio = suma/contador;
row.Cells[6].Value = promedio;
indice = 2;
promedio = 0;
suma = 0;
contador = 0;
filas++;
}
}
el valor de las celdas nulas debe de ser DbNull.Value
saludos!!!! |