I want to input into a cell without clicking spread when it has focus

Posted by: joony on 8 September 2017, 2:00 pm EST

  • Posted 8 September 2017, 2:00 pm EST

    I have lots of textbox and a spread in windows form.
    A focus is moved to spread if enter key is pressed  in a speicific text
    I want to input into the first cell of it rightly without clicking when it has a focus.
    In other words I'd don't want to use mouse.
    Though I set editmode to true, Messagebox tells 'false'
    Following is my code;
            private void teRemk_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)13 && mode == "new")
                {
                    sprAccinfo_Sheet1.SetActiveCell(0, 0);
                    sprAccinfo.EditMode = true;
                    sprAccinfo.Focus();
                    // I tried reorder the above lines, but it's useless.                

                    MessageBox.Show(sprAccinfo.EditMode.ToString());   //The output is 'False'
                }
            }

    What's wrong in my code?
    What shall I do to do this?


     

  • Replied 8 September 2017, 2:00 pm EST

    Joony,

    In case the spread gets focus when you hit enter key on a particular text box and you want to set the Active cell to be in edit mode, then I used the below snippet in the KeyPress event of the TextBox and it seems to be working fine at my side. Below is the snippet is in VB.net:

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
       If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Enter) Then
                FpSpread1.Focus()
                FpSpread1.ActiveSheet.SetActiveCell(0, 0)
                FpSpread1.EditMode = True
      End If
    End Sub

     Thanks

  • Replied 8 September 2017, 2:00 pm EST

    I tested your code in new application. 
    It worked well.
    But it doesn't work when I inserted following code;

        fpSpread1.ActiveSheet.Rows.Add(0, 1);           
      
    The spread don't have any rows when the form load.
    I added a row to input new data.
    Why doesn't this code work after adding  the above code?


    Please review if there are any problems in this code.
            private void teRemk_KeyPress(object sender, KeyPressEventArgs e)
            {
                if (e.KeyChar == (char)13 && mode == "new")
                {
                    fpSpread1.ActiveSheet.Rows.Add(0, 1);           // 
                    fpSpread1.Focus();
                    fpSpread1.ActiveSheet.SetActiveCell(0, 0);
                    fpSpread1.EditMode = true;


                    MessageBox.Show(fpSpread1.EditMode.ToString());
                }
            }


     

  • Replied 8 September 2017, 2:00 pm EST

    Joony,

    Do you also have ColumnCount set to 0 along with RowCount on form load, if that is the case then the snippet would work however you would not see any thing, so in addition to adding a row you can also add a column at index 0 or you can set the RowCount to 0 and leave the ColumnCount setting as it is, then the provided snippet will work.e.g:

      FpSpread1.ActiveSheet.Columns.Add(0, 1)

    Hope this helps. Thanks

  • Replied 8 September 2017, 2:00 pm EST

    When the form loads, the rowcount is set to 0 and column header properties like caption or alignment is set at design time.
    I'm sorry but I can't understand what you wrote in last post. Maybe cause my english is poor.

      FpSpread1.ActiveSheet.Columns.Add(0, 1)

    I tried to add the above code to my project but it failed to work.

    1. When the form loads, rowcount is 0 and columncount is over 1.
    2. A row is added by pressing a button.
    3. Without using mouse I want to input data to cell right away when a spread has focus.

    What shall I do to do this?

  • Replied 8 September 2017, 2:00 pm EST

    Joony,

    As per the requirement mentioned from  Steps (1-3), I have created a sample project which achieves the desired behavior at my side. Using this you would not need to use the Columns.Add. Please review the attached sample and let us know your further observations. Hope this helps. Thanks


    2009/08/EditModeWithoutMouse.rar
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels