|
-
Mar 7th, 2010, 04:20 PM
#1
Thread Starter
Junior Member
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
-
Mar 7th, 2010, 04:33 PM
#2
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
-
Mar 7th, 2010, 04:36 PM
#3
Thread Starter
Junior Member
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?
-
Mar 7th, 2010, 07:44 PM
#4
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
Last edited by jggtz; Mar 7th, 2010 at 07:52 PM.
-
Mar 7th, 2010, 07:58 PM
#5
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
-
Mar 7th, 2010, 08:28 PM
#6
Thread Starter
Junior Member
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
-
Mar 7th, 2010, 08:44 PM
#7
Thread Starter
Junior Member
Re: Delete rows if
It doesn't matter if it take a long time. I have about 1000 rows.
-
Mar 8th, 2010, 01:45 AM
#8
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
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 04:54 AM
#9
Thread Starter
Junior Member
Re: Delete rows if
No chances. Still the same error.
I dont understand why.
-
Mar 8th, 2010, 04:55 AM
#10
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Mar 8th, 2010, 12:28 PM
#11
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
-
Mar 8th, 2010, 06:40 PM
#12
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
-
Mar 10th, 2010, 08:57 AM
#13
Thread Starter
Junior Member
Re: Delete rows if
Perfect thanks.
Now it works with
Code:
For i = .Rows -1 To 0 Step -1
-
Mar 10th, 2010, 05:57 PM
#14
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|