Re: Datagrid multiple row selections
- From: "Mark J. McGinty" <mmcginty@xxxxxxxxxxxxxxx>
- Date: Sun, 3 Apr 2005 18:31:01 -0700
"eman2005" <eman2005@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:F1745039-7BF0-444E-9F9B-314E0E978766@xxxxxxxxxxxxxxxx
> It is possible to press Ctrl and make multiple selections of separate rows
> (e.g. 2, 3 6, 8, 11, 12,...etc) in a datagrid.
> That is great, but useless.
>
> If I hit the delete button, it prompts that it cannot delete multiple
> selections.
>
> What is the use of allowing multiple selections if you cannot use it to
> move, copy or delete the selected rows?????
Who says you can't? It's true the grid does not do it for you, but this is
not to say it can't be done.
You must first process the grid's Error event, setting the Response
parameter to 0 to bypass the default error message. In the same handler,
the attempt to delete multiple rows can be detected based on the error
value, see the example below (which assumes the grid control is named
"Grid".)
Private Sub Grid_Error(ByVal DataError As Integer, Response As Integer)
Response = 0
If DataError = dbgDelMultRows Then DeleteSelectedRows
End Sub
My handler above calls a function that I wrote to do the job, here it is in
a nutshell:
' First you'll need to make a clone of the recordset that's bound to the
grid
' If you try to use the same recordset, the record pointer changes cause
' strange behavior. If it's not a clone, the bookmarks will not be
valid.
Dim BmkArray()
' Check to see if multiple rows have been selected, if so allocate space
in
' an array and copy the bookmarks. The copy is necessary because any
' changes to the number of records in the recordset tend to screw-up
' this collection
'
If (Grid.SelBookmarks.Count > 0) Then
ReDim BmkArray(Grid.SelBookmarks.Count - 1)
For i = Grid.SelBookmarks.Count - 1 To 0 Step -1
BmkArray(i) = Grid.SelBookmarks(i)
Next
Else
' handle a single selection
ReDim BmkArray(0)
BmkArray(0) = Grid.Bookmark
If (IsNull(BmkArray(0))) Then Exit Sub
End If
' Loop through the array and delete the records referenced by the
bookmarks
'
For i = 0 To UBound(BmkArray)
rs.ActiveConnection.Errors.Clear
rs.Bookmark = BmkArray(i)
If rs.ActiveConnection.Errors.Count > 0 Then Exit For
rs.Delete
rs.MoveFirst
Next
-Mark
> --
> Eman FATiH
> Technical Communicator
> www.smartistek.com
>
.
- Follow-Ups:
- Re: Datagrid multiple row selections
- From: eman2005
- Re: Datagrid multiple row selections
- References:
- Datagrid multiple row selections
- From: eman2005
- Datagrid multiple row selections
- Prev by Date: Datagrid multiple row selections
- Next by Date: Re: error handle on '0 row selected' - re post!
- Previous by thread: Datagrid multiple row selections
- Next by thread: Re: Datagrid multiple row selections
- Index(es):
Relevant Pages
|