章鱼哥出品—VB.NET DataGridView绑定数据源 "与货币管理器的位置关联的行不能设置为不可见" 问题的解决

DtaGridView绑定数据源后,如果想让数据条件显示的话,直接使用  My_Row.Visible = False就会出错,错误类型是 "与货币管理器的位置关联的行不能设置为不可见" ,如果你遇到这样的问题,那么可以参考一下的代码。
 作者:章鱼哥,QQ:3107073263 群:309816713    
'如有疑问或好的建议请联系我,大家一起进步    
  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            Dim cm As CurrencyManager = BindingContext(DataGridView1.DataSource)
            cm.SuspendBinding() '将绑定挂起
            For Each My_Row As DataGridViewRow In DataGridView1.Rows
                If Trim(My_Row.Cells(0).Value) = "小明" Then
                    My_Row.Visible = True
                ElseIf Not My_Row.Cells(0).Value = "" Then '忽略最后一行空行
                    My_Row.Visible = False
                End If
            Next
            cm.ResumeBinding() '恢复绑定
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        'Button1.Enabled = True
        'Button2.Enabled = False
    End Sub



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值