Does SortRange update tags associated with rows in sheet?

Posted by: ashish01 on 8 September 2017, 1:14 pm EST

  • Posted 8 September 2017, 1:14 pm EST

    <FONT face=Arial>Hi</FONT>

    <FONT face=Arial>In our application we use Tag attribute of Row and Column objects extensively. Now as automatix sorting only sorts selection model and not the underlyining data model, I captured AutoSortingColumn event and here is the code snippet</FONT> 

            <SPAN class=kwd>private void</SPAN> mainSpread_AutoSortingColumn(<SPAN class=kwd>object</SPAN> sender, AutoSortingColumnEventArgs e)
    FarPoint.Win.Spread.SortInfo[] sort = <SPAN class=kwd>new</SPAN> FarPoint.Win.Spread.SortInfo[1];
    sort[0] = <SPAN class=kwd>new</SPAN> FarPoint.Win.Spread.SortInfo(0, <SPAN class=kwd>true</SPAN>, System.Collections.Comparer.Default);
    mainSheet.SortRows(0, <SPAN class=kwd>true</SPAN>, <SPAN class=kwd>true</SPAN>);
    <SPAN class=cmt>//mainSheet.SortRange(0, e.Column, mainSheet.RowCount, mainSheet.ColumnCount, true, sort);
    //e.Cancel = true;</SPAN>
    <P> <FONT face=Arial>But even after doing this, I get reference to old (unsorted) rows when using Tags (unique for each row).</FONT>

    <FONT face=Arial>Can you please tell me how to do this correctly?</FONT>

    <FONT face=Arial>Thanks</FONT>

    <FONT face=Arial>Ashish</FONT>

  • Replied 8 September 2017, 1:14 pm EST

    Ashis -

    When you use the SortRows method the tags will move with the sorted rows and columns.  So if row 4 had a tag of "Row4" and its new position is at row 15 it will still have a tag of "Row4".  This is the intended behavior.  If you use SortRange the tags will not be sorted.
  • Replied 8 September 2017, 1:14 pm EST

    <FONT face=Arial>Ok</FONT>

    <FONT face=Arial>My requirment is that once sorting is initiated by the user the data model is in sync with the data displayed on the screen.</FONT>

    <FONT face=Arial>Ex. Row 4 had tag "Row4" and index 3.  So ActiveSheet.Rows["Row4"].index returns 3. </FONT>

    <FONT face=Arial>Now after sorting say its index was modified to 13, so now ActiveSheet.Rows["Row4"].index should return 13.</FONT>

    <FONT face=Arial></FONT> 

    <FONT face=Arial>Can this be done?</FONT>

    <FONT face=Arial>Thanks</FONT>

    <FONT face=Arial>Ashish</FONT>

  • Replied 8 September 2017, 1:14 pm EST


    WHen you call the SortRows method in Spread, the View of Spread is what is sorted. The underlying DataModel is not sorted. This is to make the Spread perform more effeciently. Because of this, you will now have two coordinate systems; the DataModel and the Viewport. There are two methods (GetViewRowFromModelRow and GetModelRowFromViewRow) that you can use to translate coordinates from one to the other.

  • Replied 8 September 2017, 1:14 pm EST

    <FONT face=Arial>Thanks a lot scotts</FONT>

    <FONT face=Arial>Changing </FONT>

    <FONT face=Arial color=#0000ff>mainSheet.Rows[tag]</FONT>

    <FONT face=Arial>to</FONT>

    <FONT face=Arial color=#0000ff>mainSheet.Rows[mainSheet.GetViewRowFromModelRow(mainSheet.Rows[tag].Index)]</FONT>

    <FONT face=Arial>worked.</FONT>

    <FONT face=Arial>Thanks</FONT>

    <FONT face=Arial>Ashish</FONT>

Need extra support?

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

Learn More

Forum Channels