vb.net如果它的所有单元格都为空则删除行 [英] vb.net remove row if all it's cell is empty

查看:159
本文介绍了vb.net如果它的所有单元格都为空则删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



您是否知道如何检查连续的所有单元格是否为空以及如何删除它?

谢谢!



-xo

Hi all,

Do you have any idea on how to check if all the cells in a row is empty and how to remove it?
Thanks!

-xo

推荐答案

检查



check it

Sub CheckEmptyCellOnRowThenRemove()
        Dim rw As DataGridViewRow

        Dim rowToDelete As Int32

        If DataGridView1.RowCount > 1 Then
            For r = DataGridView1.RowCount - 2 To 0 Step -1
                rw = DataGridView1.Rows(r)
                rw.Selected = True
                Dim strCheck As String = ""
                For c = 0 To DataGridView1.ColumnCount - 1
                    If Not IsNothing(rw.Cells(c).Value) Then
                        strCheck = strCheck & rw.Cells(c).Value.ToString.Trim
                    End If
                Next
                If strCheck = "" Then
                    rowToDelete = Me.DataGridView1.Rows.GetFirstRow(DataGridViewElementStates.Selected)
                    If rowToDelete > -1 Then
                        Me.DataGridView1.Rows.RemoveAt(rowToDelete)
                    End If
                End If
                rw.Selected = False
            Next
        End If
    End Sub


这篇关于vb.net如果它的所有单元格都为空则删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆