Gridview特定行的行数

时间:2014-09-22 09:03:16

标签: c# datagridview rowcount

我有数据网格视图,其中有些行是红色的,有些是绿色的,现在我想获得仅绿色的行的行数。如何获得

以下是我改变颜色的方法

for (int i = IndexNumberOfGridReceiver; i < WhatsAppCheckTotal - 1; i++)
{
    if (form1.gridReceiver.Rows[i].Cells[1].Value.ToString().Equals(csvRow))
    {
        form1.gridReceiver.Rows[i].DefaultCellStyle.ForeColor = Color.Green;
    }
    else
    {
        form1.gridReceiver.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
    }
    IndexNumberOfGridReceiver = i;
}

1 个答案:

答案 0 :(得分:0)

你被困在哪里?

int greenRows = 0;
for (int i = IndexNumberOfGridReceiver; i < WhatsAppCheckTotal - 1; i++)
{
    if (form1.gridReceiver.Rows[i].Cells[1].Value.ToString().Equals(csvRow))
    {
        greenRows++;
        form1.gridReceiver.Rows[i].DefaultCellStyle.ForeColor = Color.Green;
    }
    else
    {
        form1.gridReceiver.Rows[i].DefaultCellStyle.ForeColor = Color.Red;
    }
    IndexNumberOfGridReceiver = i;
}