如何更新列c#中datagridview中显示的所有数据

时间:2016-06-25 14:02:43

标签: c# datagridview

我有这段代码:

var groups = netflow.OrderByDescending(x => x).GroupBy(x => x).Select(x => x.Key).ToArray();
var rank = netflow.Select(x => Array.IndexOf(groups, x)+1);

我想用rank变量更新datagridview中出现的所有数据。我已经尝试过这段代码:

int[] rankResult = rank;
for (int ii = 0; ii < rankResult.Length; ii++)
{
     string empNumb = dataGridView1[dataGridView1.Columns["empNumb"].Index, ii].Value.ToString();
     RC.updateRank(rankResult[ii], empNumb, period, year);
}

1 个答案:

答案 0 :(得分:0)

我建议您将代码更改为:

var rankResult = rank.ToList(); // Or int[] rankResult = rank.ToArray<int>();
for (int ii = 0; ii < rankResult.Length; ii++)
{
     string empNumb = dataGridView1[dataGridView1.Columns["empNumb"].Index, ii].Value.ToString();
     RC.updateRank(rankResult[ii], empNumb, period, year);
}