Delete row in MSflexgrid4

Hello all,

I would like to create a button in my form that if i select a row in my MSFlexgrid4, it will ask me if i really want to delete that row and if i click yes, it will delete it.

I dont know if also i select more than 1 row, it could delete all of them at the same time.

Could you help me with that please?

Thanks again for your help.
LVL 11
Wilder1626Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wilder1626Author Commented:
For now, i have this code but it only do one at a time, not a selection of multiple rows.

MSFlexGrid4.RemoveItem (MSFlexGrid4.Row)
0
bingieCommented:
You're almost there - you only need now to identiy the selected starting and ending rows. You can use the .Row to determine the index of the first selected row and .RowSel to determine the index of the last selected row.
Here is a function that you can use for any flexgrid - just pass to the function the name of the flex grid. So, if your flexgrid is MsFlexGrid4 then you can call the delete routien by:

Call RemoveSelectedRowsFromFG(MSFlexGrid1)


Private Sub RemoveSelectedRowsFromFG(fg As MSFlexGrid)
'Prompt user to confirm row(s) deletion
If MsgBox("Do you really want to delete the selected row(s)?", vbCritical + vbYesNo) = vbYes Then
    'User has selected yes, so delete the rows
    Dim i As Integer
    For i = fg.RowSel To fg.Row Step -1
        fg.RemoveItem (i)
    Next i
End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rajvihariCommented:

Private Sub RemoveSelectedRowsFromFG(fg As MSFlexGrid)
'Prompt user to confirm row(s) deletion
If MsgBox("Do you really want to delete the selected row(s)?", vbCritical + vbYesNo) = vbYes Then
    'User has selected yes, so delete the rows
    Dim i As Integer
    For i = fg.RowSel To fg.Row Step -1
        fg.RemoveItem (i)
    Next i
End If
End Sub

Open in new window

0
Wilder1626Author Commented:
Thank you so much.

It's perfect.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.