实现鼠标点击单元格显示...按钮,点击按钮,弹出对话框,选中后在相应的单元格显示Text,并绑定单元格Value值。...

1.创建子编辑器,该编辑器可以创建一个form,然后设计好form界面,并编写相应代码。

2.创建子编辑器类

 public class mySubEdit : Form1, FarPoint.Win.Spread.CellType.ISubEditor
    {
        public event EventHandler ValueChanged;
        public event EventHandler CloseUp;
        public Form1 frm;
        public mySubEdit_GoodsChice()
        {
            this.View1.DoubleClick += new EventHandler(View1_DoubleClick);
        }
        private void View1_DoubleClick(object sender, EventArgs e)
        {
            if (this.View1.Rows.Count > 0)
            {
                if (ValueChanged != null)
                    ValueChanged(this, EventArgs.Empty);
                if (CloseUp != null)
                    CloseUp(this, EventArgs.Empty);
            }
        }
        public Point GetLocation(Rectangle rect)
        {
            Point pt = new Point(0);
            Size sz = GetPreferredSize();
            pt.Y = 0;// (Screen.PrimaryScreen.WorkingArea.Height / 2) - (sz.Height / 2);
            pt.X = (Screen.PrimaryScreen.WorkingArea.Width / 2) - (sz.Width / 2);
            return pt;
        }
        public Control GetSubEditorControl()
        {
            return this;

        }
        public object GetValue()
        {
            return  "1,一达软件"; //

        }
        public void SetValue(object value)
        {
            // value = "";
        }

        public Size GetPreferredSize()
        {
            return new Size(this.Width, Screen.PrimaryScreen.WorkingArea.Height);
        }
    }

3.在Form_Load事件对fpSpread进行初始化设置

   fpSpread1.HorizontalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.AsNeeded;//只有当需要的时候才显示水平滚动条
            fpSpread1.VerticalScrollBarPolicy = FarPoint.Win.Spread.ScrollBarPolicy.AsNeeded; //只有当需要的时候才显示垂直滚动条
            fpSpread1.ActiveSheet.GrayAreaBackColor = Color.White; //整个sheet表的背景设置成白色

            fpSpread1.ActiveSheet.ColumnCount = 2;
            fpSpread1.ActiveSheet.Rows.Count = 10;
            fpSpread1.ActiveSheet.Columns[0].Visible = false;
   
            fpSpread1.ActiveSheet.ColumnHeader.Columns[0].Label = "存酒名称";
            fpSpread1.ActiveSheet.ColumnHeader.Columns[1].Label = "存酒数量";

            fpSpread1.ActiveSheet.Columns[0].Width = 200;
            fpSpread1.ActiveSheet.Columns[1].Width = 100;

            FarPoint.Win.Spread.CellType.NumberCellType NumberCellType = new FarPoint.Win.Spread.CellType.NumberCellType();
            NumberCellType.DecimalPlaces = 1;

            fpSpread1.ActiveSheet.Columns[1].CellType = NumberCellType;

            FarPoint.Win.Spread.CellType.TextCellType TextCellType = new FarPoint.Win.Spread.CellType.TextCellType();
            mySubEdit subEditor = new mySubEdit();
            TextCellType.SubEditor = subEditor;

            fpSpread1.ActiveSheet.Columns[0].CellType = TextCellType;

编写fspRead的以下两个事件代码:

    private void fpSpread1_EditModeOn(object sender, EventArgs e)
        {
            if (fpSpread1.ActiveSheet.ActiveCell.Column.Index == 1)
            {
                FarPoint.Win.Spread.CellType.GeneralEditor c = this.fpSpread1.EditingControl as FarPoint.Win.Spread.CellType.GeneralEditor;
                c.ButtonStyle =FarPoint.Win.ButtonStyle.PopUp;  //用于显示...效果的按钮
            }
        }

        private void fpSpread1_SubEditorClosed(object sender, FarPoint.Win.Spread.SubEditorClosedEventArgs e)
        {
           //当子编辑器被关闭时,将子编辑器的Text属性值拆分数组,并分别绑定到单元格的Text和Value属性
            string[] arr = e.EditingControl.Text.ToString().Split(',');
            fpSpread1.ActiveSheet.ActiveCell.Value = arr[0];
            fpSpread1.ActiveSheet.ActiveCell.Text = arr[1];
        }

 

Ok,Enjoy it.

转载于:https://www.cnblogs.com/edsoft/archive/2012/02/22/2363975.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值