隐藏DGV行onload / TabPage选择

时间:2015-02-10 21:46:11

标签: vb.net winforms datagridview

想知道为什么我无法成功运行此代码onload或选择tabpage时 - (将在点击按钮时运行)

For Each Row In DataGridView1.Rows

            If Not Row.index = 0 And Row.index < DataGridView1.Rows.Count - 1 Then

                If Not Row.Cells(6).Value = WhoIsIt Then
                    Row.Visible = False
                Else
                    Row.Visible = True
                End If

            Else

                If Not Row.Cells(6).Value = WhoIsIt And Row.index < DataGridView1.Rows.Count Then
                    Row.DefaultCellStyle.BackColor = Color.Black
                End If

            End If

        Next

背景:DGV连接到访问表。我的目标是让它只显示在单元格中检查用户姓名首字母的行。

1 个答案:

答案 0 :(得分:0)

只需使用此代码

即可
for i as integer =0 to DataGridView1.Rows.Count - 1   
       if DataGridView1.Rows(i).Cells(6).Value <> WhoIsIt then  
          DataGridView1.Rows(i).visible=false  
       end if  
next