如何使用vb.net中的RowFilter从datagridview中排除或修剪空白单元格

时间:2013-08-07 19:05:51

标签: vb.net datagridview datasource rowfilter

我正在尝试在导入时找到一种在datagridview中删除或修剪空白单元格的方法。我在网上找到了一些关于与数据源一起使用的rowfilter的东西。现在这就是我宣布我的数据源的方式

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

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

1 个答案:

答案 0 :(得分: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