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?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.