Re: Datagrid multiple row selections

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




"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
>


.



Relevant Pages

  • Re: Datagrid multiple row selections
    ... replaced Grid with my grid name grdTrtComp ... >> It is possible to press Ctrl and make multiple selections of separate rows ... > ' First you'll need to make a clone of the recordset that's bound to the ...
    (microsoft.public.vb.database.ado)
  • Re: Datagrid multiple row selections
    ... another grid. ... >>> It is possible to press Ctrl and make multiple selections of separate rows ... >> ' First you'll need to make a clone of the recordset that's bound to the ...
    (microsoft.public.vb.database.ado)
  • RE: Query using multiple listbox selections
    ... Now I can insert multiple columns from the ... Dim ctl As Control ... Dim varItem As Variant ... I'd like to pass all of the selections into a query, ...
    (microsoft.public.access.reports)
  • RE: Multiple-select from list
    ... If you are talking about putting multiple s in the list box item (1 ... of the List Box control to put together a where condition for your SQL ... Dim strWhere as String ... I want to be able to make multiple selections on my form from the same field ...
    (microsoft.public.access.forms)
  • Re: Creating separate tables for multi-select list box selections
    ... Request Database) and one that contains the values the populate the list ... boxes to end up in the corresponding fields of the main table (tblPSB Request ... form to be able to select multiple items from a list. ... multiple selections from a listbox and store them in multiple rows of a child ...
    (microsoft.public.access.forms)