2015-02-10 49 views
0

奇怪,爲什麼我不能成功的onload運行這段代碼時或標籤頁中選擇 - (將按鈕點擊運行)隱藏DGV行爲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連接到訪問表。我的目標是讓它只顯示在被檢查的單元格中具有用戶名縮寫的行。

回答

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