Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

deleting multiple records at once in flexgrid

Status
Not open for further replies.

mhedrick

Programmer
Apr 21, 2005
5
US
Hello,
I am having a problem with deleting multiple records in a flexgrid. Here is the code snippet:

Dim varRowCount As Integer
Dim ii As Integer
delinvno = TextInvno.Text
varRowCount = Cwayflex.Rows - 1

For ii = 0 To varRowCount

If Cwayflex.TextMatrix(ii + 1, COL_DELETEEXTRACWAY) = "1" Then
Cwayflex.RemoveItem Cwayflex.Row
varRowCount = Cwayflex.Rows
End If

Next ii

Basically I have an empty first column if the user select the column. A little check appears that tells them that the row(s) is selected. There is
an extra column that is marked "1" when the check appears. So I scan the rows for the "1" value. It deletes the first value find but the rowcount is not reset. I tried to reset the rowcount right after a row is deleted but it still increments past the number of rows and gives the "out of script error" Any suggestions would be greatly appreciated.
Thanks,
M.
 
Do it backwards
Code:
Dim varRowCount As Integer
Dim ii As Integer
delinvno = TextInvno.Text
varRowCount = Cwayflex.Rows - 1
   
   [COLOR=blue]For ii = varRowCount To 0 Step -1[/color]
        
      If Cwayflex.TextMatrix(ii + 1, COL_DELETEEXTRACWAY) = "1" Then
         Cwayflex.RemoveItem Cwayflex.Row
         varRowCount = Cwayflex.Rows
      End If
            
   Next ii
 
It's not pretty, but it works.

Dim varRowCount As Integer
Dim ii As Integer
varRowCount = Cwayflex.Rows - 1
ii = 0

While ii <= varRowCount
If varRowCount <= 1 Then Exit Sub
If Cwayflex.TextMatrix(ii, COL_DELETEEXTRACWAY) = "1" Then
Cwayflex.RowSel = ii
Cwayflex.RemoveItem Cwayflex.RowSel
varRowCount = Cwayflex.Rows - 1
ii = 0
End If
ii = ii + 1
Wend
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top