0

我正在尝试找到一种方法来删除或修剪导入时我的 datagridview 中的空白单元格。我在网上找到了一些关于与数据源一起使用的行过滤器的信息。现在这就是我声明我的数据源的方式

 DataGridView1.DataSource = DS.Tables(0).DefaultView

如果有人可以给我一些建议或告诉我如何使用行过滤器修剪空白单元格,我将不胜感激!

4

1 回答 1

0

如果您不想删除带有空白单元格的行,您可以使用 LINQ 轻松隐藏它们:

Public Sub HideDataGridViewCells(ByVal dgv As DataGridView)
    Dim EmptyCells = (From Cell As DataGridViewCell In (From Row As DataGridViewRow In dgv.Rows.Cast(Of DataGridViewRow)() Select Row.Cells).Cast(Of DataGridViewCell)() Where Trim(Cell.Value.ToString).Equals("") Select Cell)
    For Each Cell As DataGridViewCell In EmptyCells
        Cell.OwningRow.Visible = False
    Next
End Sub
于 2013-08-07T20:51:50.790 回答