Appropriate rows not selected upon sorting columns

Posted by: vikascpatil123 on 8 July 2018, 5:38 pm EST

    • Post Options:
    • Link

    Posted 8 July 2018, 5:38 pm EST

    Hi,

    I am selecting a row ( for ex: 4th row) where I am using spread control. Now when I sort a column, the data shuffles and the selection is still on the 4th row.

    Is there a property where, the selection automatically happens on the row which was previously selected?

  • Posted 9 July 2018, 10:15 pm EST

    Hello,

    You can use below mentioned code for the same:-

       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            GetSelections()
            FpSpread1.Sheets(0).SortRows(1, True, False)
            ReselectBlock()
        End Sub
        Dim rows() As Integer
    
        Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
            GetSelections()
            FpSpread1.Sheets(0).SortRows(1, False, False)
            ReselectBlock()
        End Sub
    
        Private Sub GetSelections()
            Dim cr() As FarPoint.Win.Spread.Model.CellRange
            Dim rArrayList As New ArrayList
            cr = FpSpread1.Sheets(0).GetSelections
            For Each crItem As FarPoint.Win.Spread.Model.CellRange In cr
                For i As Integer = 0 To crItem.RowCount - 1
                    rArrayList.Add(FpSpread1.Sheets(0).GetModelRowFromViewRow(crItem.Row + i))
                Next
            Next
            rows = rArrayList.ToArray(GetType(Integer))
        End Sub
    
        Private Sub ReselectBlock()
            FpSpread1.Sheets(0).Models.Selection.ClearSelection()
            For i As Integer = 0 To rows.Length - 1
                FpSpread1.Sheets(0).Models.Selection.AddSelection(FpSpread1.Sheets(0).GetViewRowFromModelRow(rows(i)), -1, 1, -1)
            Next
        End Sub
    

    Hope it helps.

    Thanks,

    Reeva

Need extra support?

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

Learn More

Forum Channels