在switch语句中使用datagrid值

时间:2013-01-04 19:11:02

标签: c# datagrid switch-statement

在我的程序中,我有一个datagridview表c_tbl,它从SQL Server获取数据并填充datagridview。我有一个for循环遍历每一行。现在我有一个switch语句,应检查每一行并获取值,以便我可以比较它并在该行中添加其他数据。

这就是它的样子

for(int i=0; i<c_tbl.rows.count; i++){
      switch("this is where i need the argument that will check the row and column value)
      {
         case "string value that gets compared"
                  //add in values to column on same row. 
       }
}

我最初有类似

的东西
switch(c_tbl.Column[0][i]) 

但它不起作用。

1 个答案:

答案 0 :(得分:0)

你可以像这样循环DataTable

foreach (DataRow row in c_tbl.Rows)
{
    foreach (DataColumn col in c_tbl.Columns)
    {
        switch (row[col].ToString())
        {
        }
    }
}