FarPoint Spread 基础知识

本文介绍了 FarPoint Spread 控件的基本操作,包括获取行列信息、设置单元格格式、增删行列、单元格导航及编辑、多行选择移除、剪切复制粘贴等功能,并提供了撤销恢复、查找过滤排序等高级功能的实现方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.获得当前行的行号,列号,总列数,总行数

                int rowCount = fpSpread1.ActiveSheet.RowCount;
                int colCount = fpSpread1.ActiveSheet.Columns.Count;
                int activeRow = fpSpread1.ActiveSheet.ActiveRowIndex;
                int activeCol = fpSpread1.ActiveSheet.ActiveColumnIndex;

2.设置单元格格式时候用 MultiColumnComboBoxCellType 是注意:只能用字符类型字段的选择。要想用数字字段选择的话须将数字类型转换为字符型即可。

ContractedBlock.gifExpandedBlockStart.gifCode
  FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType mCombox = new FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType();
            mCombox.ColumnEditName 
= "customerCode";
            mCombox.DataColumnName 
= "customerCode";
            mCombox.ListWidth 
= 556;
            mCombox.MaxDrop 
= 8;
            mCombox.DataSourceList 
= dataset;

            fpSpread1.ActiveSheet.Columns[
0].Label = "customerCode";
            fpSpread1.ActiveSheet.Columns[
0].CellType = mCombox;

3.问题:当下拉mCombox 中的数据少时会出现空白单元格,目前还不知道咋回事!

4.增加和刪除行

      fpSpread1.ActiveSheet.Rows.Add(rowCount, rows);rowCount是添加行的起始位置,rows是添加的行數。

      fpSpread1.ActiveSheet.Rows.Remove(rowCount, rows);rowCount是刪除行的起始位置,rows刪除的行數。

5.

 if (fpSpread1.ActiveSheet.ActiveRow.Index == fpSpread1.ActiveSheet.RowCount - 1) //如果是到最后一行則增加一行
            {
                if (e.KeyCode == Keys.Down)
                {
                    DetailAdd();
                }
            }
            if (e.KeyCode == Keys.Delete)  //按delete鍵可刪除當前活動單元格內容
            {
                fpSpread1.ActiveSheet.ActiveCell.ResetValue();
            }
            if (e.KeyCode == Keys.Enter)  //按Enter鍵跳到下一單元格
            {
                int rowCount = fpSpread1.ActiveSheet.RowCount;
                int colCount = fpSpread1.ActiveSheet.Columns.Count;
                int activeRow = fpSpread1.ActiveSheet.ActiveRowIndex;
                int activeCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
                if (activeCol != (colCount-1))
                {
                    fpSpread1.ActiveSheet.SetActiveCell(activeRow, activeCol + 1);
                }
                else if( activeRow != (rowCount - 1))
                {
                    fpSpread1.ActiveSheet.SetActiveCell(activeRow+1,0);
                }
            }

6.移除选择的多行

               int rowCount = fpSpread1.ActiveSheet.RowCount;
                for (int row = 0; row < rowCount; row++)   //移除選擇行
                {
                    if (fpSpread1.ActiveSheet.IsSelected(row, 1) == true)
                    { fpSpread1.ActiveSheet.Rows.Remove(row, 1); }
                }

7.剪切,复制,粘贴

            //剪切:
            FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction = new        FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
        fpSpread1.UndoManager.PerformUndoAction(cutAction);      
            //复制      
detail.ActiveSheet.ClipboardCopy();

            //粘贴
            FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction pasteAction = new FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction(ClipboardPasteOptions.All);
            detail.UndoManager.PerformUndoAction(pasteAction);

 

ContractedBlock.gifExpandedBlockStart.gifCode
SheetView sv = fpSpread1.ActiveSheet;
      
if (sv == null)
        
return;
      
int activeRow = sv.ActiveRowIndex;
      
int activeColumn = sv.ActiveColumnIndex;
      
if (sender == menuCut) //剪切
      {
        FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction 
= new FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
        fpSpread1.UndoManager.PerformUndoAction(cutAction);
      }
      
else if (sender == menuCopy) //复制
      {
        sv.ClipboardCopy();
      }
      
else if (sender == menuPaste) //粘贴
      {
        FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction pasteAction 
= new FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction(ClipboardPasteOptions.All);
        fpSpread1.UndoManager.PerformUndoAction(pasteAction);
      }
      
else if (sender == menuInsertRow) //插入一行
      {
        sv.Rows.Add(activeRow, 
1);
      }
      
else if (sender == menuInsertColumn)//插入一列
      {
        sv.Columns.Add(activeColumn, 
1);
      }
      
else if (sender == menuRemoveRow)//删除一行
      {
        sv.Rows.Remove(activeRow, 
1);
      }
      
else if (sender == menuRemoveColumn)//删除一列
      {
        sv.Columns.Remove(activeColumn, 
1);
      }
      
else if (sender == menuClearContents) //清除内容
      {
        FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction 
= new FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
        fpSpread1.UndoManager.PerformUndoAction(cutAction);
      }

 8.撤销,恢复

ContractedBlock.gifExpandedBlockStart.gifCode
//撤销
FarPoint.Win.Spread.InputMap im;
im 
= fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(
new FarPoint.Win.Spread.Keystroke(Keys.U, Keys.None), FarPoint.Win.Spread.SpreadActions.Undo);
//恢复
FarPoint.Win.Spread.InputMap im;
im 
= fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(
new FarPoint.Win.Spread.Keystroke(Keys.E, Keys.None), FarPoint.Win.Spread.SpreadActions.Redo);

 9.Find,Filter,Sort

ContractedBlock.gifExpandedBlockStart.gifCode
//允许列排序
this.fpSpread1_Sheet1.Columns.Get(0).AllowAutoSort = true;
//允许列过滤
fpSpread1.ActiveSheet.Columns.Get(1).AllowAutoFilter = true;
//查找
fpSpread1.SearchWithDialogAdvanced(04"This"truetruefalsefalse00);


 

转载于:https://www.cnblogs.com/Tonyyang/archive/2008/09/04/1284102.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值