Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EndEdit after pressing left or right keys #15

Closed
Xcone opened this issue May 23, 2017 · 3 comments
Closed

EndEdit after pressing left or right keys #15

Xcone opened this issue May 23, 2017 · 3 comments

Comments

@Xcone
Copy link

Xcone commented May 23, 2017

Hi,

I've implemented behavior when pressing left or right when editing a cell for WinForms.
I wanted to implement it for WPF and Android as well, but I couldn't get it compiling. I did change project settings for #WPF, but I seems there's more to it.
I'm also not really familiar with Git. I'm a mercurial user and not really active in online repos. So I had a bit of trouble attempting to get this code to you. So instead posting it below in the issue.

If you're interested in adding this change; replacing the OnKeyDown method of the InputTextBox in the WinForms control of Reogrid with the code below should do the trick. I guess it's peanuts for you to implement the same behavior in WPF and android as well.

I also want to point out that default Excel behavior when pressing "ENTER" while editing a cell will move the selection to the cell below. In your behavior you move to the right. Of course I don't know how literally you want to mimic Excel with these kind of behaviors?

Thanks!

           protected override void OnKeyDown(KeyEventArgs e)
            {
                var sheet = owner.currentWorksheet;

                if (sheet.currentEditingCell != null && Visible)
                {
                    bool isProcessed = false;

                    // in single line text
                    if (!TextWrap && Text.IndexOf('\n') == -1)
                    {
                        isProcessed = true;
                        if (e.KeyCode == Keys.Up)
                        {
                            ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionUp());
                        }
                        else if (e.KeyCode == Keys.Down)
                        {
                            ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionDown());
                        }
                        else if (e.KeyCode == Keys.Left && SelectionStart == 0)
                        {
                            ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionLeft());
                        }
                        else if (e.KeyCode == Keys.Right && SelectionStart == Text.Length)
                        {
                            ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionRight());
                        }
                        else
                        {
                            isProcessed = false;
                        }
                    }

                    if (!isProcessed)
                    {
                        if (!Toolkit.IsKeyDown(Win32.VKey.VK_CONTROL) && e.KeyCode == Keys.Enter)
                        {
                            ProcessSelectionMoveKey(e, sheet, () => sheet.MoveSelectionRight());
                        }
                    }
                }
            }

            private void ProcessSelectionMoveKey(KeyEventArgs e, Worksheet sheet, Action moveAction)
            {
                e.SuppressKeyPress = true;
                sheet.EndEdit(Text);
                moveAction();
            }
@jingwood
Copy link
Member

Thanks! Welcome to fork and submit any your changes to this repository of source code.

I've implemented behavior when pressing left or right when editing a cell for WinForms.
I wanted to implement it for WPF and Android as well, but I couldn't get it compiling. I did change project settings for #WPF, but I seems there's more to it.

You can just open the ReoGridWPF.sln solution to build WPF edition. And open the ReoGridAndroid.sln to build Android edition.

Android build requires Xamarin development environment and runtime.
And make sure you are on the develop branch and use the latest source code.

I also want to point out that default Excel behavior when pressing "ENTER" while editing a cell will move the selection to the cell below. In your behavior you move to the right. Of course I don't know how literally you want to mimic Excel with these kind of behaviors?

You can set the movement direction by using this property:

// move right
worksheet.SelectionForwardDirection = SelectionForwardDirection.Right;

// move down
worksheet.SelectionForwardDirection = SelectionForwardDirection.Down;

See https://reogrid.net/document/behavior/

@Xcone
Copy link
Author

Xcone commented May 24, 2017

I applied the change in my own fork and created pull request #16. I hope I did it correctly.

I completely missed the setting you refer to! Thanks. That covers what I need, aside that it had inconsistent behavior between navigating cells and editing a cell. The pull request fixes that as well.

@jingwood
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants