回复 10楼iceman的帖子
刚刚尝试做了个例子,
虽然可以解决掉升序降序转换的问题,
但是以点击列最优先,然后以从左到右的列依次升序或降序排列的功能没有实现,可是debug下查看sorter的内容,确实是被点击列排在最前面,然后从左到右的列依次放入的sorter。
或许理解错了,sorter内容的顺序并不会影响到排序的优先顺序?
还是说有什么其他的原因。
代码如下,方便参考:
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace WindowsApplication1
- {
- public partial class Form1 : Form
- {
- bool isAsc = true;//true:ASC false:DESC
- int clickColIndex = -1;//ColumnIndex has been Clicked
- public Form1()
- {
- InitializeComponent();
- this.fpspdX.ActiveSheet.RowCount = 10;
- this.fpspdX.ActiveSheet.ColumnCount = 10;
- this.fpspdX.Sheets[0].Columns[0,9].AllowAutoSort = true;
- }
- private void fpspdX_CellClick(object sender, FarPoint.Win.Spread.CellClickEventArgs e)
- {
- if (e.ColumnHeader == true && e.Column > -1 && e.Column < 10)//Column1~Column10
- {
- if (!e.RowHeader)//Header
- {
- int colAct = e.Column;
- if (clickColIndex == colAct)//
- {
- //ASC <=> DESC
- if (isAsc == true)
- {
- isAsc = false;
- }
- else
- {
- isAsc = true;
- }
- clickColIndex = colAct;//to memo
- }
- FarPoint.Win.Spread.SortInfo[] sorter = new FarPoint.Win.Spread.SortInfo[10];
- //First
- sorter[0] = new FarPoint.Win.Spread.SortInfo(colAct, isAsc, System.Collections.Comparer.Default);
- //
- int index = 1;
- for (int i = 0; i < 10; i++)
- {
- if (i == colAct)
- {
- continue;
- }
- else
- {
- sorter[index] = new FarPoint.Win.Spread.SortInfo(i, isAsc, System.Collections.Comparer.Default);
- index = index + 1;
- }
- }
- fpspdX.ActiveSheet.SortRows(0, fpspdX.ActiveSheet.RowCount, sorter);
- }//END FOR if (!e.RowHeader)
- }
- }
- }
- }
复制代码 |