實現鼠標點擊單元格顯示...按鈕,點擊按鈕,彈出對話框,選中后在相應的單元格顯示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.


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com