Results 1 to 4 of 4

Thread: Multiple Row Select on DataGrid

  1. #1

    Thread Starter
    Fanatic Member Mindcrime's Avatar
    Join Date
    Jun 2001
    Location
    Peterborough, UK
    Posts
    555

    Multiple Row Select on DataGrid

    I know how to select multiple Rows on an ADO DataGrid by holding down the CTRL Key.

    I would like to hold down the vbKeyShift to select Multiple rows at once. For example select row 1, hold down shift, select row 20 then rows 1 to 20 become Bookmarked.

    I have trapped the Shift key in KeyDown, but the code I put in RowColumnChange works while the procedure is working, but all bookmarks are removed (or the grid clears these).

    Code:
    Private Sub grdItemData_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
    
        If KeyCode = vbKeyShift Then
            MultiLineSelect = True
        End If
        
    End Sub
    Private Sub grdItemData_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
        If MultiLineSelect = True Then
            For myIndex = LastRow To grdItemData(Index).Row
                grdItemData(Index).SelBookmarks.Add (myIndex)
            Next myIndex
        End If
    End Sub
    Help!
    Mindcrime : )
    ICQ 24003332

    VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Use TrueDBGrid (www.componentone.com) - it allows multi-selection by simply changing a property.
    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3

    Thread Starter
    Fanatic Member Mindcrime's Avatar
    Join Date
    Jun 2001
    Location
    Peterborough, UK
    Posts
    555
    I downloaded the eval version and it does allow this.
    I think we will go down this route.

    However I have acheived this using the ActiveX DataGrid (mention in my original thread).

    Code:
    Private Sub grdItemData_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyShift Then
            MultiLineSelect = True
        End If
    End Sub
    Private Sub grdItemData_RowColChange(Index As Integer, LastRow As Variant, ByVal LastCol As Integer)
        If MultiLineSelect = True Then
            MultiLineSelectStartRow = LastRow
            MultiLineSelectEndRow = grdItemData(Index).Row
        End If
    End Sub
    Private Sub grdItemData_KeyUp(Index As Integer, KeyCode As Integer, Shift As Integer)
        If KeyCode = vbKeyShift Then
            For myIndex = MultiLineSelectStartRow To MultiLineSelectEndRow
                grdItemData(Index).SelBookmarks.Add (myIndex)
            Next myIndex
            MultiLineSelect = False
        End If
    End Sub
    For those who want to be picky, it only shows the selection after the shift key is released.

    But what the hell!
    Mindcrime : )
    ICQ 24003332

    VB 5.0, VB 6.0 SP5, COM, DCOM, VB.NET Beta 2, Oracle 8

  4. #4
    New Member
    Join Date
    Feb 2017
    Posts
    8

    Re: Multiple Row Select on DataGrid

    Hi,

    I have a VB6 project that needs to be support for a while.
    I have a question about the solution is provided here.

    It works as long as the recordset is not filtered or sorted.
    If you sort or filter, the .row index won't be sequential anymore and multi selection doesn't work properly.
    Any solutions?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width