Sort DataModel and ViewModel

Posted by: afallas on 8 September 2017, 1:02 pm EST

  • Posted 8 September 2017, 1:02 pm EST

    Hi,


    How can I sort the Data Model and View Model at the same time? I need to sort the View Model because I'm changing the background color of some rows; so I should use SortRows. I also need to sort the Data Model because the user can export the grid to Excel (I should use SortRange).


    Thanks

  • Replied 8 September 2017, 1:02 pm EST

    Hi,


    There is no "SaveAsViewed" flag. I tried "SaveAsFiltered" but didn't work.


    I don't know if I'm getting something wrong but I tought SortRows sorts the view only and SortRange sorts the DataModel.

  • Replied 8 September 2017, 1:02 pm EST

    Use the SortRange method.
  • Replied 8 September 2017, 1:02 pm EST

    Hello,


    You can use the SortRange method as Bob stated to sort the View and the DataModel. However, this is slow. I would suggest sticking with the SortRows method and then when saving to Excel using the "SaveAsViewed" ExcelSaveFlag to save the data sorted.

  • Replied 8 September 2017, 1:02 pm EST

    The SaveAsViewed flag is only in version 4.  The SortRange will sort both.
  • Replied 8 September 2017, 1:02 pm EST

    I have the following code and it doesn't work (Win Spread v3.0.2005.2005):


    sp.ActiveSheet.RowCount = 10


    sp.ActiveSheet.ColumnCount = 1


    For i As Integer = 0 To 9


    sp.ActiveSheet.Cells(i, 0).Text = 10 - i


    Next


    sp.ActiveSheet.Rows(0).BackColor = Color.Chocolate


    sp.ActiveSheet.Rows(4).BackColor = Color.CornflowerBlue


    Dim si As FarPoint.Win.Spread.SortInfo() = {New FarPoint.Win.Spread.SortInfo(0, True)}


    sp.ActiveSheet.SortRange(0, 0, sp.ActiveSheet.RowCount, sp.ActiveSheet.ColumnCount, True, si)


    After the call to SortRange the rows 0 and 4 that have a different backcolor stay in the same position. They should move with the data. I can achieve that with SortRows but then when the data is exported to Excel it appears unsorted. Hence, SortRange only sorts the Data not the View.


     

  • Replied 8 September 2017, 1:02 pm EST

    Hello,


    Your code is only sorting the cells in the Spread, but these colors are associated with the Rows. In order to sort the entire row and not just the data in the row, you need to change your call to SortRange.

     
    		Dim si As FarPoint.Win.Spread.SortInfo() = {New FarPoint.Win.Spread.SortInfo(0, True)}

    sp.ActiveSheet.SortRange(-1, -1, -1, -1, True, si)
     
  • Replied 8 September 2017, 1:02 pm EST

    Thank you, this solved my problem. Perhaps it will  be good to document this behavior in the SortRange method. Currently the documentation doesn't say anything about the use of -1 as arguments.
Need extra support?

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

Learn More

Forum Channels