-1

您好,我在网上找到了这段代码,它似乎可以满足我的要求。但是它是用我不熟悉的 c# 编写的。任何可以将其转换为 vb.net 的多语言程序员?我非常感谢您提供的任何帮助!

foreach (DataGridViewColumn clm in grdView.Columns)
{
Bool FoundData = false;
foreach (DataGridViewRow row in grdView.Rows)
{
     if (row.Cells[clm.Index].Value.ToString() != string.Empty)
     {
         FoundData = true;
         break;
     }
}
if (!FoundData)
{
     grdView.Columns[clm.Index].Visible = false;
}
}
4

3 回答 3

5

尝试这个:

For Each clm As DataGridViewColumn In grdView.Columns
    Dim FoundData As Boolean = False
    For Each row As DataGridViewRow In grdView.Rows
        If row.Cells(clm.Index).Value.ToString() <> String.Empty Then
            FoundData = True
            Exit For
        End If
    Next
    If Not FoundData Then
        grdView.Columns(clm.Index).Visible = False
    End If
Next
于 2013-08-08T15:13:02.700 回答
1

您可以使用任何在线转换工具。http://www.carlosag.net/tools/codetranslator/

 For Each clm As DataGridViewColumn In grdView.Columns
   Dim FoundData As Bool = false
 For Each row As DataGridViewRow In grdView.Rows
    If (row.Cells(clm.Index).Value.ToString <> string.Empty) Then
        FoundData = true
        Exit For
    End If
 Next
 If Not FoundData Then
    grdView.Columns(clm.Index).Visible = false
 End If
 Next
于 2013-08-08T15:37:19.103 回答
0

试试这个工具。您可能会发现它对未来的转换很有帮助:http: //www.developerfusion.com/tools/convert/vb-to-csharp/

于 2013-08-08T21:52:28.293 回答