Problem with column sorting

Posted by: gemini11 on 8 September 2017, 12:47 pm EST

  • Posted 8 September 2017, 12:47 pm EST

    I am reading in a csv file and then trying to turn column sorting on for each column.  The sort indicator appears for each column, but nothing happens if I try and click on the diamond.  I have used this feature before when I manually enabled each column using the Spread Designer, and that worked fine.  The sheet setting - operational mode is set to "Extended Select".

    Here is the code fragment that I am using to read and then enable sorting.

    <FONT size=2><FONT size=2>

    fpSpread1.ActiveSheet.LoadTextFile(openFileDialog1.FileName, </FONT><FONT color=#0000ff size=2>true</FONT><FONT size=2>, FarPoint.Win.Spread.Model.</FONT><FONT color=#2b91af size=2>IncludeHeaders</FONT><FONT size=2>.None, </FONT><FONT color=#a31515 size=2>"\n"</FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2>","</FONT><FONT size=2>, </FONT><FONT color=#a31515 size=2>""</FONT><FONT size=2>);

    </FONT></FONT><FONT color=#0000ff size=2></FONT>

    <FONT color=#0000ff size=2>for</FONT><FONT size=2> (</FONT><FONT color=#0000ff size=2>int</FONT><FONT size=2> i = 0; i < fpSpread1.ActiveSheet.ColumnCount; i++)


    fpSpread1.ActiveSheet.SetColumnAllowAutoSort(i, </FONT><FONT color=#0000ff size=2>true</FONT><FONT size=2>);

    </FONT><FONT size=2>


    Any help would be greatly appreciated.


  • Replied 8 September 2017, 12:47 pm EST

    <FONT size=2>

    I tried setting the Operation Mode to Normal and the sort indicators are still not active.

    It may be a moot point now, as I upgraded from V2.5 to V3.0 while I was on your site today, and the sort indicators now work fine.

    My problem now is that I don't want to sort the first six rows of the sheet, as they just contain some fixed info in column 1 and no data.

    I tried freezing the first 6 rows, and they do not scroll, but they still sort.

    Any ideas?

    Thanks again,

  • Replied 8 September 2017, 12:47 pm EST


    My guess is the problem is due to having OperationMode set to Extended Select. However, this should work, and did in my test. Try setting the OperationMode to Normal. If the sorting works, make sure you have the latest maintenance release and set the OperationMode back to Extended Select to test again.

  • Replied 8 September 2017, 12:47 pm EST


    You would need to implement your own sort to get this functionality. You can catch the AutoSortingColumn event and set the Cancel parameter to True. This will stop the default processing of the Spread to sort the column. Then, programatically, you can call the SortRows method passing in the range of rows you want to use to sort.

  • Replied 8 September 2017, 12:47 pm EST

    What about putting your static data in the ColumnHeader? Is that a possibility?

  • Replied 8 September 2017, 12:47 pm EST

    Excellent suggestion!  I tried putting the static data into multiple column header rows, and that works great.  Much easier than the previous method I was using of manually handling the sort event.

    The final issue I am fighting is that is seems to sort numeric data starting from the right-most digit, so a row with a 28 gets put before a row with a value of 9.  I tried changing the column cell type to a numeric cell, and the behavior didn't change.  I know the cell was converted to a number, as it now displays the value with 2 decimal places.

    I don't seem to find a way to get numbers sorted by numeric value.

  • Replied 8 September 2017, 12:47 pm EST


    The sorting is done based on the data type in the Spread. The CellType will not have any bearing on how the data is sorted. You need to make sure you put the values in the cells as numbers and not strings.

Need extra support?

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

Learn More

Forum Channels