GridDesktop

Good day


I wonder if you could assist.

I would like to replicate the MS Excel functionality where a locked cell isn’t allowed focus. Allowing the user to tab through only the unlocked cells.

Is this functionality available within the GridDesktop?

Regards
Wayne

Hi Wayne,


Thank you for contacting Aspose support.

I have tested the case while using the latest version of Aspose.Cells.GridDesktop and I believe that your required feature may not be available at the moment. Please note, I have tested the scenario by protecting a few cells using the Aspose.Cells.GridDesktop.Worksheet.SetProtected method however, while navigating through the cells using the tab, the protected cells still gets selected. We will log this requirement in our database to provide it with future releases of the component. It would be appropriate that you share the steps to lock the cells in Excel manually in order to exhibit the desired behaviour so we could attach those details to the request for product team’s review.

Hi Babar


Thanks for the reply.

I’ve managed to solve the issue with implementing some code in the FocusedCellChanged event.
Below is my solution. I’ve also attached a video of how to reproduce in Excel.

Public prevSelection As Aspose.Cells.GridDesktop.CellLocation
Public bBusy As Boolean = False

Private Sub GridDesktop1_FocusedCellChanged(sender As Object, e As Aspose.Cells.GridDesktop.CellEventArgs) Handles GridDesktop1.FocusedCellChanged

If bBusy = True Then Exit Sub
Dim cell As Aspose.Cells.GridDesktop.GridCell = GridDesktop1.GetActiveWorksheet.GetFocusedCell 'e.Cell
Dim loc As Aspose.Cells.GridDesktop.CellLocation = cell.Location
Dim style As Aspose.Cells.GridDesktop.Style = cell.GetStyle()
Dim sheet As Aspose.Cells.GridDesktop.Worksheet = GridDesktop1.GetActiveWorksheet()

If prevSelection Is Nothing Then prevSelection = cell.Location

If style.CellLocked = True Then

Dim directionRow As Integer = 0
Dim directionCol As Integer = 0
If prevSelection.Row < cell.Location.Row Then
directionRow = 1
ElseIf prevSelection.Row > cell.Location.Row Then
directionRow = -1
End If
If prevSelection.Column < cell.Location.Column Then
directionCol = +1
ElseIf prevSelection.Column > cell.Location.Column Then
directionCol = -1
End If

If directionCol <> 0 Then
Dim iRow As Long = cell.Location.Row
Dim iStartCol As Long
Dim iEndCol As Long
Dim iStep As Long
If directionCol < 0 Then
iStartCol = cell.Location.Column
iEndCol = 0
iStep = -1
Else
iStartCol = cell.Location.Column
iEndCol = GridDesktop1.GetActiveWorksheet.ColumnsCount
iStep = 1
End If
Dim bFound As Boolean = False
bBusy = True
For col As Integer = iStartCol To iEndCol Step iStep
sheet.SetFocusedCell(New Aspose.Cells.GridDesktop.CellLocation(iRow, col))
If GridDesktop1.GetActiveWorksheet.GetFocusedCell.Style.CellLocked = False Then
prevSelection = New Aspose.Cells.GridDesktop.CellLocation(iRow, col)
bFound = True
Exit For
End If
Next
If bFound = False Then
sheet.SetFocusedCell(New Aspose.Cells.GridDesktop.CellLocation(prevSelection.Row, prevSelection.Column))
prevSelection = New Aspose.Cells.GridDesktop.CellLocation(prevSelection.Row, prevSelection.Column)
End If
bBusy = False
End If

If directionRow <> 0 Then
Dim iCol As Long = cell.Location.Column
Dim iStartRow As Long
Dim iEndRow As Long
Dim iStep As Long
If directionRow < 0 Then
iStartRow = cell.Location.Row
iEndRow = 0
iStep = -1
Else
iStartRow = cell.Location.Row
iEndRow = GridDesktop1.GetActiveWorksheet.RowsCount
iStep = 1
End If
Dim bFound As Boolean = False
bBusy = True
For row As Integer = iStartRow To iEndRow Step iStep
sheet.SetFocusedCell(New Aspose.Cells.GridDesktop.CellLocation(row, iCol))
If GridDesktop1.GetActiveWorksheet.GetFocusedCell.Style.CellLocked = False Then
prevSelection = New Aspose.Cells.GridDesktop.CellLocation(row, iCol)
bFound = True
Exit For
End If
Next
If bFound = False Then
sheet.SetFocusedCell(New Aspose.Cells.GridDesktop.CellLocation(prevSelection.Row, prevSelection.Column))
prevSelection = New Aspose.Cells.GridDesktop.CellLocation(prevSelection.Row, prevSelection.Column)
End If
bBusy = False
End If

Else
prevSelection = GridDesktop1.GetActiveWorksheet.GetFocusedCell.Location()
End If

End Sub


Hi Wayne,


Thank you for sharing the solution and video.

I have logged a formal request in our database as CELLSNET-44243 for product team’s review. Please spare us little time for proper feasibility analysis of your request. As soon as we completed the preliminary analysis, we will share the details here for your kind reference,

@wayne_za

Thanks for using Aspose APIs.

This is to inform you that we have fixed your issue CELLSNET-44243 now. We will soon provide the fix after performing QA and including other enhancements and fixes.

@wayne_za

Thanks for using Aspose APIs.

Please download and try the following fix and let us know your feedback.

The issues you have found earlier (filed as CELLSNET-44243) have been fixed in latest version of Aspose.Cells for .NET (Download | NuGet).