代码之家  ›  专栏  ›  技术社区  ›  Yohan Greenburg

获取数据网格上点的最大值

  •  -1
  • Yohan Greenburg  · 技术社区  · 8 年前

    不可开票成员的DataGridViewRow。单元格不能像方法一样使用

    这是我的语法-在我的datagrid中获得列1的最大值的合适方法是什么?

    double MaxVal = 0;
    foreach (DataGridViewRow row in HeightGrid.Rows)
    {
        if (row.Cells(1).Value > MaxVal)
        {
            MaxVal = row.Cells(1).Value;
        }
    }
    
    2 回复  |  直到 8 年前
        1
  •  2
  •   C. Helling    8 年前

    要获得最大值:

    MaxVal = dataGridView.Rows.Cast<DataGridViewRow>()
                        .Max(r => Convert.ToDouble(r.Cells[1].Value));
    

    Cells[1]

    var biggestRow = dataGridView.Rows.Cast<DataGridViewRow>()
                        .Aggregate((r1,r2) => Convert.ToDouble(r1.Cells[1].Value) > Convert.ToDouble(r2.Cells[1].Value) ? r1 : r2);
    

    这将为您提供第二列中具有最大值的行。从那里,可以提取第一个和第二个单元格。

        2
  •  0
  •   Philip Schiff    8 年前

    这意味着细胞是一个 所有物 ,不是 ,因此应作为DataGridViewRow访问。单元格,而不是DataGridViewRow.Cells()。

    推荐文章