Selected row colors in "RowMode"

Posted by: pauld on 19 February 2019, 6:44 pm EST

    • Post Options:
    • Link

    Posted 19 February 2019, 6:44 pm EST - Updated 30 September 2022, 1:59 pm EST

    We have a grid with OperationMode set to “RowMode”.

    As expected, when you click in a row, the row’s background color becomes black and the foreground color becomes white (ie. inverted; the exact colors are unimportant).

    As expected, the current cell that has focus shows as “unselected” (white backcolor, black forecolor).

    Only one column is editable, all other columns are locked.

    QUESTIONS:

    Can we prevent the locked cells from changing to the “unselected” appearance?

    Can we prevent focus from moving to any locked cell?

    What we are looking for is the grid row to be selected with only the editable cell able to receive focus and display with the “unselected” colors.

    The “Undesirable” image shows what we don’t want to happen when clicking in a cell in the first column. The “Desired” image shows what we want the grid to look like, no matter which column we click in.

    Thanks.

    – Paul

  • Posted 19 February 2019, 6:45 pm EST

    Note: The top image is the “Undesirable” and the bottom image is the “Desired”.

  • Posted 20 February 2019, 1:31 am EST

    Hi,

    You can use the SelectionChanged event and check if the current ActiveCell is Locked. Accordingly, you can move the focus to a an editable cell in that row:

    private void FpSpread1_SelectionChanged(object sender, FarPoint.Win.Spread.SelectionChangedEventArgs e)
    {
        if (fpSpread1.ActiveSheet.ActiveCell.Locked)
        {
            fpSpread1.ActiveSheet.SetActiveCell(e.Range.Row, 2);
        }
    }
    

    You can refer to the attached sample for complete example.

    Regards,

    Jitender

    PreventFocusOnLockedCells.zip

  • Posted 20 February 2019, 2:45 pm EST

    Jitender,

    Thanks for the reply.

    Unfortunately, I cannot run you sample because of, I presume, Spread version differences; your project has some references I don’t have at all.

    I see what your code is doing and tried it in my project, but it did not work.

    None of the cells in my grid are showing as locked, therefore, the active cell is not being changed.

    The main difference between our code is that my grid does not use a datasource, the cells are manually assigned values using “SetText()”.

    I wouldn’t see why that would make a difference, but I’ll leave it up to you to tell me.

    As replacement code, I skip the lock test and just reset the active cell all the time for the current row. It works, but I would like to know why the locked property is always false.

    – Paul

  • Posted 20 February 2019, 8:39 pm EST

    Further, if you double-click in a cell, the focus stays on the cell clicked on; selection changed is triggered on the first click but not the second.

    And, the double-click event is not triggered so you can’t catch it that way.

    Any other possibilities?

    – Paul

  • Posted 21 February 2019, 12:39 am EST

    Hi Paul,

    The sample I posted used the latest version of Spread (v12). You’re probably using an older version. Since there are some significant changes in v12, can you please share the version you’re using so we can help you accordingly?

    If you’re using any version earlier than Spread 12, then Cell.Locked would return false since Locked is only set on columns (irrespective of whether you’re using a DataSource or not). In earlier versions, Spread uses different Style objects for cell, row, and columns. See this doc: https://help.grapecity.com/spread/SpreadNet11/WF/webframe.html#spwin-knowobjparentage.html

    So, you should check the Locked property on the column instead of the cells.

    If you do want to check the Locked property of the cell, you should use this code:

    if (fpSpread.ActiveSheet.Models.Style.GetCompositeInfo(fpSpread.ActiveSheet.ActiveRowIndex, 
                        fpSpread.ActiveSheet.ActiveColumnIndex, -1, null).Locked)
    {
        // Move the focus to the editable-cell is current cell is Locked.
        fpSpread.ActiveSheet.SetActiveCell(e.Range.Row, 2);
    }
    

    For this case, there was a handler for EditError in the sample. Have you used it?

    Please refer to the updated sample which uses Unbound mode, and Spread 11.

    Regards,

    Jitender

    PreventFocusOnLockedCells_Unbound.zip

  • Posted 22 February 2019, 2:14 pm EST

    Jitender,

    Everything worked perfectly with the sample you sent.

    I’m good.

    Thanks for all the help!

    – Paul

Need extra support?

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

Learn More

Forum Channels