2016-02-27 69 views
0

我正在使用VB6並且在其中使用MSFlexGrid現在我想刪除用戶選擇的完整行,並且一旦自動完成,將焦點設置爲文本框,同時在Internet上搜索有用的,但問題是,當我點擊按鈕,它刪除所有的行,即使是第一行,這是FlexGrid的頭,我不想刪除第一行。如何從msflexgrid中刪除所選項目

這裏是代碼

Private Sub cmdDell_Click() 
Dim i As Integer 

    With grdArticles 'the msflexgrid 
     If .RowSel <> 0 Then 'check if there is a selected row 
      For i = .RowSel To .Rows - 2 'loop from selected row to the las row 
       .TextMatrix(i, 0) = .TextMatrix(i + 1, 0) 'set rows with 1 back 
       .TextMatrix(i, 1) = .TextMatrix(i + 1, 1) 
       .TextMatrix(i, 2) = .TextMatrix(i + 1, 2) 
       .TextMatrix(i, 3) = .TextMatrix(i + 1, 3) 
      Next i 
       .Rows = .Rows - 1 'make the rows 1 less 
     Else 
      MsgBox "Selecet row to delete!!!", vbExclamation 
     End If 
    End With 
End Sub 

回答

0

如果你只允許你只需要使用

Me.MSFlexGrid1.RemoveItem Me.MSFlexGrid1.RowSel

一次選擇一行如果您可以選擇多個行(用戶單擊並拖動以選擇多個行),則需要確定所選行的範圍並單獨刪除每行。此頁面上的代碼顯示如何獲取所選行的開始和結束。刪除行時,您需要反向循環。

http://www.vb-helper.com/howto_tell_flexgrid_rows_selected.html