章鱼哥出品—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

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...