2017-05-03 85 views
0

我使用下面的子程序使特定的行不可见,但是当我回到过滤的datagridview并尝试循环显示行索引时,它会从列顶部到列的底部而不是按顺序(1,2,3 ...等)。Datagridview行不可见,行选择随机

我已经能够将过滤器后的当前设置设置为顶部可见行,但这没有什么区别。

Private Sub BR_VAL_NO_SHOW() 

    Dim dgv As DataGridView = Me.dgvStockCheck_Available 
    Dim cm1 As CurrencyManager = CType(BindingContext(dgv.DataSource), CurrencyManager) 

    Try 
     For i As Integer = 0 To dgv.Rows.Count - 1 

      If IsDBNull(dgv.Rows(i).Cells("MATERIAL").Value) Then 
       Exit Try 
      Else 

       If Not dgv.Rows(i).Cells("MATERIAL").Value = "SLAT" Then 
        dgv.CurrentCell = Nothing 
        cm1.SuspendBinding() 
        dgv.Rows(i).Visible = False 
       End If 
      End If 

     Next 
    Catch ex As Exception 

    End Try 

End Sub 

回答

0

这是完全正常的

你给本小区的NOTHING

值,但您使用IsDBNull来验证这是不一样的东西。

不要混淆没有的概念与DBNull的对象面向对象的编程语言 。在面向对象编程语言中,Nothing表示没有对象的引用。 DBNul l代表未初始化的变体不存在的数据库 列。

来源:https://msdn.microsoft.com/en-us/library/system.dbnull(v=vs.90).aspx

这样的解决方案可能是只检查是否可见或不可见。

If dgv.Rows(i).Visible = False Then 
    'Not Visible 
    Exit Try 
Else