【发布时间】:2014-02-10 13:37:13
【问题描述】:
我想将DataGridviewRow 作为ref 传递给它的单元格,但我无法做到这一点
foreach(DataGridViewRow dgr in dgvMarksEntryByClassWise.Rows)
{
RowValueSet(ref dgr);
}
这里给出编译时错误,因为 dgr 是 foreach iteration variable
我也尝试用for loop 来做到这一点
for (int i = 0; i < dgvMarksEntryByClassWise.Rows.Count; i++)
{
RowValueSet(ref dgvMarksEntryByClassWise.Rows[i]);
}
但这里也出现编译时错误:A property,indexer or dynamic member acces cannot passed as an out reference
我参考了这个关于上述错误的问题,但没有找到任何适合我的问题的解决方案
- foreach iteration variable
- A property,indexer or dynamic member acces cannot passed as an out reference
请告诉我如何做到这一点
更新代码
void RowValueSet(ref DataGridViewRow dgr)
{
dgr.Cells["StudentZero"].Value = ss.Where(w => w.MarksheetMarks == "0").Count();
if (ss.Count() != 0)
dgr.Cells["StudentISEmpty"].Value = Convert.ToInt16(lblTotlatStudent1.Text) - ss.Count();
else
dgr.Cells["StudentISEmpty"].Value = 0;
dgr.Cells["StudentEntry"].Value = ss.Count();
}
【问题讨论】:
-
你能显示
RowValueSet的代码吗? -
@Damith 我更新了我的 codd
-
没有理由 RowValueSet 需要 ref 传递的行。只需传入它,您的代码应该可以正常工作。
-
我听不懂@DaveShaw
-
只需从您的
RowValueSet方法中删除ref并查看它是否有效,我看不出任何通过引用传递的理由。DataGridViewRow已经是一个引用类型。
标签: c# for-loop datagridview foreach iteration