-
Delete rows if
Hello all.
I need your help with a code.
I would like to remove rows in my MSFlexgrid: If Form13.MSFlexGrid1.TextMatrix(i, 7) <> Form12.Com_window.Text Then
I only want to remove rows that match the criteria from the Form12.Com_window.Text.
Code:
Private Sub cmdApply4_Click()
Dim i As Integer, j As Integer, fgRowRemove%
For i = Form13.MSFlexGrid1.Rows To 1 Step -1
If Form13.MSFlexGrid1.TextMatrix(i, 8) <> Form12.Com_window.Text Then
fgRemoveRow Form13.MSFlexGrid1, i
End If
Next i
End Sub
With this code, i have an error:Sub or function not define.
How can i fix that please?
Thanks for your help
-
Re: Delete rows if
Code:
Private Sub cmdApply4_Click()
Dim i As Integer, j As Integer, fgRowRemove%
For i = Form13.MSFlexGrid1.Rows To 1 Step -1
If Form13.MSFlexGrid1.TextMatrix(i, 8) <> Form12.Com_window.Text Then
Form13.MSFlexGrid1.RemoveItem ( i )
End If
Next i
End Sub
JG
-
Re: Delete rows if
Hello jggtz.
I've just try it and now, i have another error.
runtime error '381' subscript out of range
Code:
If Form13.MSFlexGrid1.TextMatrix(i, 8) <> Form12.Com_window.Text Then
Do you know why?
-
Re: Delete rows if
Sorry, didn't see it, You can't remove all the rows
Code:
Private Sub cmdApply4_Click()
Dim i As Integer, j As Integer, fgRowRemove%
For i = Form13.MSFlexGrid1.Rows To 2 Step -1
If Form13.MSFlexGrid1.TextMatrix(i, 8) <> Form12.Com_window.Text Then
Form13.MSFlexGrid1.RemoveItem ( i )
End If
Next i
End Sub
-
Re: Delete rows if
If you have a large number of rows to delete, using a For/Next loop could take some serious time and hang your application.
As an alternative, you can simply reduce the number of rows by resetting the control's Rows property. Normally, this property returns the total number of rows in the grid. However, you can also use it to remove rows. For instance, if your flexgrid currently contained 15 rows, and you wanted to reduce them to 10, you could simply issue the following code statement:
Code:
MSFlexGrid1.Rows = 9
-
Re: Delete rows if
Hello,
Sorry but still the same error on:
If Form13.MSFlexGrid1.TextMatrix(i, 8) <> Form12.Com_window.Text Then
runtime error '381' subscript out of range
-
Re: Delete rows if
It doesn't matter if it take a long time. I have about 1000 rows.
-
Re: Delete rows if
Try this
Code:
Private Sub cmdApply4_Click()
Dim i As Long
With Form13.MSFlexGrid1
For i = .Rows To 1 Step -1
If .TextMatrix(i, 8) <> Form12.Com_window.Text Then
If (.Rows > .FixedRows + 1) Then
.RemoveItem (i)
Else
.Rows = .FixedRows
End If
End If
Next i
End With
End Sub
-
Re: Delete rows if
No chances. Still the same error.
I dont understand why.
-
Re: Delete rows if
-
Re: Delete rows if
Like with many things in programming, the first item in a FlexGrid is 0, and 1 is the second, etc.
The .Rows property returns the amount of rows, which is 1 higher than the last row (when there are 2 rows, they will be 0 and 1).
As such, this is probably what you want:
Code:
For i = .Rows -1 To 0 Step -1
-
Re: Delete rows if
AFAIK, You can't remove all the rows
You cant't remove fixed row and the last row
As I posted
Code:
For i = Form13.MSFlexGrid1.Rows To 2 Step -1
As koolsid posted
Code:
If (.Rows > .FixedRows + 1) Then
-
Re: Delete rows if
Perfect thanks.
Now it works with
Code:
For i = .Rows -1 To 0 Step -1
-
Re: Delete rows if
If I try this code :
Code:
For I = .Rows - 1 To 0 Step -1
.RemoveItem (I)
Next I
I get
You Can't Remove the last non fixed row
JG