ReoGrid Forum

Fast and powerful .NET Spreadsheet Component

You are not logged in.

Announcement

This forum has been archived and no longer accepts new user registrations. Please report your questions, problems, and feedback to the issue page of ReoGrid on GitHub. Thank you for your cooperation.

https://github.com/unvell/ReoGrid/issues

#1 2015-09-11 08:38:38

asparatu
Member
Registered: 2014-08-20
Posts: 196

BeforeCellkeyDown Event

Hello Jing,
    I have this code that you give me while ago about testing CTRL+A key down event. As of the new version this does not work anymore or did you change something? From what i can see everything fires but nothing happens.. I test in another form that i took this code from that I know was working and it does not work anymore.

Event

AddHandler rgDataGatheringSheet.BeforeCellKeyDown, Sub(ss, ee)
                                                               ee.IsCancelled = ee.KeyCode = (Keys.Control Or Keys.A)
                                                           End Sub

Method

 Private Function SelectAll(Optional e As KeyEventArgs = Nothing) As Boolean
        Dim blnTemp As Boolean = False

        If Me.ActiveControl.Name = Me.rgDataGatheringGrid.Name Then
            With rgDataGatheringSheet
                 .SelectRange(validrange)
                  'or like this, but neither is working now..
                If .ColumnCount = 4 Then
                    .SelectRange(1, (.ColumnCount - 1), (.RowCount - 1), (.ColumnCount - 1))
                Else
                    .SelectRange(1, .ColumnCount, (.RowCount - 1), (.ColumnCount))
                End If
                blnTemp = True
            End With
        ElseIf Me.ActiveControl.Name = Me.rgResultsGrid.Name Then
            With rgResultsSheet
                .SelectRange(ReoGridRange.EntireRange)
            End With
            blnTemp = True
        End If

        Return blnTemp
    End Function

Offline

#2 2015-09-11 12:16:09

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: BeforeCellkeyDown Event

Shane, is there any details of 'does not work', since I tested this code that everything works as expected.

AddHandler grid.CurrentWorksheet.BeforeCellKeyDown, Sub(ss, ee)
    If (ee.KeyCode = (Keys.Control Or Keys.A)) Then
      ee.IsCancelled = True
      grid.CurrentWorksheet.SelectRange("C3:F5")
    End If
  End Sub

Do you want to cancel the default Ctrl+A and do a customize selection? The code above can do that. Where do you call the SelectAll method?

Offline

#3 2015-09-11 17:28:00

asparatu
Member
Registered: 2014-08-20
Posts: 196

Re: BeforeCellkeyDown Event

Hello Jing,
     I think I know why it was not working right..I have test it tomorrow. The selectionmode is cell and range.
Shane

Offline

#4 2015-09-12 03:46:14

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: BeforeCellkeyDown Event

OK Good Luck!

Offline

#5 2015-09-15 07:16:56

asparatu
Member
Registered: 2014-08-20
Posts: 196

Re: BeforeCellkeyDown Event

Hello Jing,
    the reason why it was not working was because I had grid.currentworksheet.selectionmode = cell and not grid.currentworksheet.selectionmode = range, but what i did is remove the grid.currentworksheet.selectionmode = cell and it worked fine after that..

the final code

Event Code

  AddHandler grid.currentworksheet.BeforeCellKeyDown, Sub(ss, ee)
                                                         ee.IsCancelled = ee.KeyCode = (Keys.Control Or Keys.A)
                                                     End Sub

AddHandler rgDataGatheringSheet.BeforeSelectionRangeChange, Sub(s, e)
                                                                        'checks to see the select flag is true
                                                                        If m_blnSelectFlag Then Exit Sub

                                                                        ' Disable to select any cells outside validRanges
                                                                        e.IsCancelled = Not validRange.Contains(e.SelectionStart) _
                                                                            OrElse Not validRange.Contains(e.SelectionEnd)
                                                                    End Sub

Method Code

    Private Function SelectAll(Optional e As KeyEventArgs = Nothing) As Boolean
        Dim blnTemp As Boolean = False

        Select Case Me.ActiveControl.Name
            Case rgDataGatheringGrid.Name
                With rgDataGatheringSheet
                    .SelectRange(validRange)
                End With
                blnTemp = True
            Case rgResultsSheet.Name
                With rgResultsSheet
                    m_blnSelectFlag = True 'Check in the BeforeSelectionRangeChange, so it does not use validrange but total range of grid.
                    .SelectRange(ReoGridRange.EntireRange)
                    m_blnSelectFlag = False
                End With
                blnTemp = True
        End Select

        Return blnTemp
    End Function

Update: Added the BeforeSelectionRangeChange Event

Last edited by asparatu (2015-09-16 04:32:09)

Offline

#6 2015-09-15 11:10:33

Jingwood
Moderator
From: jing at reogrid.net
Registered: 2014-06-03
Posts: 615

Re: BeforeCellkeyDown Event

If SelectionMode is set to Cell, only single cell can be selected. Thanks for sharing the result.

Offline

Board footer

Powered by FluxBB