我们经常使用冻结行去显示合计信息,同时使用过滤、排序去选择查看信息。下面就通过实例讲解怎样使冻结行不参与过滤和排序。
1.初始化 Spread
private void InitSpread() { //设置行列数 this.fpSpread1.Sheets[0].RowCount = 10; this.fpSpread1.Sheets[0].ColumnCount = 10; //设置可排序、过滤列 this.fpSpread1.Sheets[0].Columns[0].AllowAutoSort = true; this.fpSpread1.Sheets[0].Columns[1].AllowAutoFilter = true; //设置冻结行 this.fpSpread1.Sheets[0].FrozenTrailingRowCount = 2; this.fpSpread1.Sheets[0].FrozenRowCount = 1; } 复制代码
2.通过 UnfilteredRows 设置不可过滤行
private void SetUnfilterRow() { int[] unfilterRows=new int[3]{0,8,9}; this.fpSpread1.Sheets[0].RowFilter.UnfilteredRows = unfilterRows; } 复制代码
3.通过 SortRows 设置不可排序行
bool ascending = true; private void fpSpread1_AutoSortingColumn(object sender, FarPoint.Win.Spread.AutoSortingColumnEventArgs e) { e.Cancel = true; ascending = !ascending; //设置可排序行 this.fpSpread1.Sheets[0].SortRows(1, 4, new FarPoint.Win.Spread.SortInfo[] { new FarPoint.Win.Spread.SortInfo(e.Column, ascending) }); } 复制代码
操作前图片展示:
测试环境:VS 2010 && Spread for WinForm 5.0