Set Focus On A Particular Cell

Posted by: bob-flaherty on 8 September 2017, 5:04 am EST

  • Posted 8 September 2017, 5:04 am EST

    Using C# 3.5 in developing a Windows app.  On one of the forms, there is a listbox and a spread control.  When the use double-clicks on a row in the listbox, data from the object stored in that row of the listbox is used to create a new row on the spread control and numerous cells in the newly created row are populated with data.


    How do you automatically set focus on a particular column in the newly created row (focus on a given cell knowing the row index and the column index) such that the user could start enter data in that cell without having tab or use the mouse?


    This requirment is not just for the ease of entering data but it would also permit the editing of the data when focus leaves the newly created row.

  • Replied 8 September 2017, 5:04 am EST

    Bob,

    You can use the SetActiveCell method of Spread to set active cell to the desired position (knowing the row and column index). Below snippet illustrates the usage of the SetActiveCell and set the focus at cell(0,1):

    <blockquote>

            Dim dt As New DataTable("TestTable")
            dt.Columns.Add("Number")
            dt.Columns.Add("Letter")
            dt.Rows.Add(New Object() {"1", "One"})
            dt.Rows.Add(New Object() {"2", "Two"})
            Dim datamodel As New FarPoint.Win.Spread.Model.DefaultSheetDataModel(dt)
            FpSpread1.ActiveSheet.Models.Data = datamodel
            FpSpread1.ActiveSheet.SetActiveCell(0, 1)

    </blockquote>

    Hope this helps.Thanks

  • Replied 8 September 2017, 5:04 am EST

    The above code makes the particular cell active but cursor focus is not there
  • Replied 8 September 2017, 5:04 am EST

    Hello,

    You need to set EditModePermanent to true for that matter. Please have a look at the code for the same:-

    fpSpread1.ActiveSheet.SetActiveCell(0, 1);
    fpSpread1.EditModePermanent = true;


    Hope it helps.

    Thanks,
    Reeva
  • Marked as Answer

    Replied 1 January 2020, 3:19 pm EST

    fpSpread1.ActiveSheet.SetActiveCell(row, col, true);
    fpSpread1.ShowActiveCell(verticalPosition, horizontalPosition);

    this code is working fine for me.
Need extra support?

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

Learn More

Forum Channels