vb代码:
Dim janTbl As Janus.Windows.GridEX.GridEXTable
For Each janTbl In lvtoolpartsinfo.Tables`
c#code:
Janus.Windows.GridEX.GridEXTable janTbl = new Janus.Windows.GridEX.GridEXTable();
foreach (janTbl in lvtoolpartsinfo.Tables)
{ }
错误:foreach语句中都需要类型和标识符
编辑:
c#code:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;
错误:
line 3:The name 'janTbl' does not exist in the current context
line 4 ...
line 5..
答案 0 :(得分:1)
删除此行:
Janus.Windows.GridEX.GridEXTable janTbl = new Janus.Windows.GridEX.GridEXTable();
然后,您只需要修复foreach
语句,以包含janTbl
的类型,然后设置:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
{
// ...
}
答案 1 :(得分:1)
你缺少大括号:
foreach (var janTbl in lvtoolpartsinfo.Tables)
{ // <--- don't forget this
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;
} // <--- and this
没有大括号,只有foreach()
语句后面的第一行才是循环的一部分。之后的代码在循环之外,就像你写的那样:
foreach (Janus.Windows.GridEX.GridEXTable janTbl in lvtoolpartsinfo.Tables)
janTbl.Columns[0].Visible = false;
janTbl.Columns[1].Caption = "Part Number";
janTbl.Columns[1].ShowRowSelector = true;
janTbl.Columns[1].EditType = Janus.Windows.GridEX.EditType.NoEdit;
janTbl.Columns[1].Width = 120;