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 2014-12-11 01:31:34

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

How to get Current cell in worksheet

I want know how can get the current cell in a worksheet.

I have this code:

 Private Sub frmScatterPlot_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown

        ' Initialize the flag to false.
        nonNumberEntered = False

        If e.Modifiers = Keys.Control AndAlso e.KeyCode = Keys.A Then
            If rgDataGatheringControlContainer.Name = Me.ActiveControl.Name Then
                rgDataGatheringControl.SelectRange(2, 1, 32, 2)
            End If
            nonNumberEntered = True
            Exit Sub
        End If

        If e.KeyCode = Keys.Escape Then
            If rgDataGatheringControlContainer.Name = Me.ActiveControl.Name Then
                With rgDataGatheringControl
                    .SelectionMode = ReoGridSelectionMode.None
                    .SelectionMode = ReoGridSelectionMode.Range
                    .FocusPos = New ReoGridPos(2, 1)
                End With
            End If
        End If
    End Sub

I have static pos but i want to get the current pos and check to make sure it is inside my range that is writable.


Shane

Offline

#2 2014-12-11 09:07:48

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

Re: How to get Current cell in worksheet

Did you mean the current editing cell? There is a method to get the editing cell.

Dim pos = worksheet.GetEditingCell()

If you want get the selected cell, the property FocusPos is used to do that.

Last edited by Jingwood (2014-12-11 09:14:30)

Offline

#3 2014-12-11 11:51:38

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

Re: How to get Current cell in worksheet

Jing,
    I mean like you would with CellEventArgs, you can get the e.row and e.column, that is what i am looking for.
I want be able to check the row and column, so i can move if they enter into readonly cell it will put in the first on column editable column.. i am looking this also when i take tab and enter keys so it only stay in that area an no were else.

In that instance i want to get current position, so when press CTRL+A and if press ESC it will go back last position before you pressed CTRL+A. That is one reason why i want to get Row and column position.

Shane

Offline

#4 2014-12-11 13:36:04

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

Re: How to get Current cell in worksheet

I guess you could use the FocusPosChanged event, and its property Position. The below code keeps focus cell always at (0,0) position.

AddHandler sheet.FocusPosChanged, Sub(s, e)
	Debug.WriteLine(e.Position.ToAddress())

	If (e.Position.Row > 0 OrElse e.Position.Col > 0) Then
		sheet.FocusPos = New ReoGridPos(0, 0)
	End If
End Sub

And for Ctrl+A, I recommend that to prevent Ctrl+A rather than put the position back to previous position, the below code will prevent the Ctrl+A:

AddHandler sheet.BeforeCellKeyDown, Sub(s, e)
	e.IsCancelled = (e.KeyCode = Keys.Control Or Keys.A)
End Sub

Last edited by Jingwood (2014-12-11 13:53:57)

Offline

#5 2014-12-11 13:46:32

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

Re: How to get Current cell in worksheet

thank you,
    I am using this code in another place.

AddHandler sheet.BeforeCellKeyDown, Sub(s, e)
	e.IsCancelled = (e.KeyCode = Keys.Control Or Keys.A)
End Sub

ok.. i see what you are talking about..

Shane

Offline

#6 2014-12-11 14:27:16

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

Re: How to get Current cell in worksheet

OK smile Let me know if you still meet this problem.

Offline

Board footer

Powered by FluxBB