您好我在网上找到了这个代码,它似乎做了我想要的。不过它是用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;
}
}
答案 0 :(得分: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
答案 1 :(得分: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
答案 2 :(得分:0)
试试这个工具。您可能会发现它对将来的转化很有帮助: http://www.developerfusion.com/tools/convert/vb-to-csharp/