예제 #1
1
        /// <summary>
        /// Initializes a new instance of the DataGridView class.
        /// </summary>
        public DataGridView()
            : base()
        {
            ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(DataGridView_ColumnHeaderMouseClick);
            ColumnHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_ColumnHeaderMouseDoubleClick);
            SortColumnIndex = -1;
            base.ColumnHeadersHeight = 26;
            DoubleBuffered = true;

            //this.MouseDown += new MouseEventHandler(DataGridView_MouseDown);
            //this.DragDrop += new DragEventHandler(DataGridView_DragDrop);
            //this.DragOver += new DragEventHandler(DataGridView_DragOver);
            //this.MouseUp +=new MouseEventHandler(DataGridView_MouseUp);
        }
예제 #2
0
        //#region Properties

        //public FormDataEntryLogic DataEntryController { get; set; }

        //public bool ViewLoading { get { return _viewLoading; } }

        //public ICollection<Tree> Trees
        //{
        //    get
        //    {
        //        return DataService.NonPlotTrees;
        //    }
        //}

        //#region DataService

        //IDataEntryDataService _dataService;

        //IDataEntryDataService DataService
        //{
        //    get { return _dataService; }
        //    set
        //    {
        //        OnDataServiceChanging();
        //        _dataService = value;
        //        OnDataServiceChanged();
        //    }
        //}

        //void OnDataServiceChanged()
        //{
        //    if (_dataService != null)
        //    {
        //        _dataService.EnableLogGradingChanged += HandleEnableLogGradingChanged;
        //    }
        //}

        //void OnDataServiceChanging()
        //{
        //    if (_dataService != null)
        //    {
        //        _dataService.EnableLogGradingChanged -= HandleEnableLogGradingChanged;
        //    }
        //}

        //void HandleEnableLogGradingChanged(object sender, EventArgs e)
        //{
        //    if (_logsColumn != null)
        //    {
        //        var logGradingEnabled = DataService.EnableLogGrading;
        //        _logsColumn.Visible = logGradingEnabled;

        //        _logToolStripMenuItem.Text = logGradingEnabled ?
        //        "Disable Log Grading" : "Enable Log Grading";
        //    }
        //}

        //#endregion DataService

        //#region AppSettings

        //private ApplicationSettings _appSettings;

        //public ApplicationSettings AppSettings
        //{
        //    get { return _appSettings; }
        //    set
        //    {
        //        OnAppSettingsChanging();
        //        _appSettings = value;
        //        OnAppSettingsChanged();
        //    }
        //}

        //private void OnAppSettingsChanging()
        //{
        //    if (_appSettings != null)
        //    {
        //        _appSettings.CruisersChanged -= Settings_CruisersChanged;
        //    }
        //}

        //private void OnAppSettingsChanged()
        //{
        //    if (_appSettings != null)
        //    {
        //        _appSettings.CruisersChanged += Settings_CruisersChanged;
        //    }
        //}

        //#endregion AppSettings

        //#endregion Properties

        ControlTreeDataGrid()
        {
            UpdatePageText();

            EditMode              = DataGridViewEditMode.EditOnEnter;
            AutoGenerateColumns   = false;
            AllowUserToDeleteRows = false;
            AllowUserToAddRows    = false;

            CellClick += new DataGridViewCellEventHandler(ControlTreeDataGrid_CellClick);

            _BS_trees = new BindingSource();
            ((System.ComponentModel.ISupportInitialize)_BS_trees).BeginInit();
            _BS_trees.DataSource = typeof(Tree);
            DataSource           = _BS_trees;
            ((System.ComponentModel.ISupportInitialize)_BS_trees).EndInit();

            ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler(ControlTreeDataGrid_ColumnHeaderMouseClick);

            _logToolStripMenuItem        = new ToolStripMenuItem();
            _logToolStripMenuItem.Name   = "logToolStripMenuItem";
            _logToolStripMenuItem.Size   = new System.Drawing.Size(180, 22);
            _logToolStripMenuItem.Click += logToolStripMenuItem_Click;

            _contexMenu = new ContextMenuStrip(new System.ComponentModel.Container());
            _contexMenu.SuspendLayout();
            _contexMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { _logToolStripMenuItem });
            _contexMenu.Name = "_contexMenu";
            _contexMenu.Size = new System.Drawing.Size(181, 26);

            _contexMenu.ResumeLayout(false);
        }
        public SpreadsheetView()
            : base()
        {
            SpreadsheetModel = new SpreadsheetModel(new CellCollection());            
            Dock = DockStyle.Fill;
            CellMouseDoubleClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_CellMouseDoubleClick);
            CellMouseClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_CellMouseClick);
            RowHeaderMouseClick += new DataGridViewCellMouseEventHandler(SpreadsheetView_RowHeaderMouseClick);
            RowHeightChanged += new DataGridViewRowEventHandler(SpreadsheetView_RowHeightChanged);
            ColumnWidthChanged += new DataGridViewColumnEventHandler(SpreadsheetView_ColumnWidthChanged);
            KeyDown += new KeyEventHandler(SpreadsheetView_KeyDown);
            KeyUp += new KeyEventHandler(SpreadsheetView_KeyUp);
            ParentChanged += delegate
            {
                Columns.Clear();

                for (int k = 0; k < ColumnCount; k++)
                {
                    Columns.Add(MakeColumnLabel(k), MakeColumnLabel(k));
                    Columns[k].SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                Rows.Add(RowCount);

                AllowUserToOrderColumns = false;
                SelectionMode = DataGridViewSelectionMode.ColumnHeaderSelect;
            };

            CellEndEdit += new DataGridViewCellEventHandler(SpreadsheetView_CellEndEdit);
            CellBeginEdit += new DataGridViewCellCancelEventHandler(SpreadsheetView_CellBeginEdit);
            RowsRemoved += new DataGridViewRowsRemovedEventHandler(SpreadsheetView_RowsRemoved);

            this.DefaultCellStyle.Font = new Font("Times", 12);
        }
        /// <summary>
        /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed.
        /// <example>
        /// datagridviewcellmouseeventhandler.BeginInvoke(sender, e, callback);
        /// </example>
        /// </summary>
        public static IAsyncResult BeginInvoke(this DataGridViewCellMouseEventHandler datagridviewcellmouseeventhandler, Object sender, DataGridViewCellMouseEventArgs e, AsyncCallback callback)
        {
            if (datagridviewcellmouseeventhandler == null)
            {
                throw new ArgumentNullException("datagridviewcellmouseeventhandler");
            }

            return(datagridviewcellmouseeventhandler.BeginInvoke(sender, e, callback, null));
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the DataGridView class.
        /// </summary>
        public DataGridView()
            : base()
        {
            ColumnHeaderMouseClick       += new DataGridViewCellMouseEventHandler(DataGridView_ColumnHeaderMouseClick);
            ColumnHeaderMouseDoubleClick += new DataGridViewCellMouseEventHandler(DataGridView_ColumnHeaderMouseDoubleClick);
            SortColumnIndex          = -1;
            base.ColumnHeadersHeight = 26;
            DoubleBuffered           = true;

            //this.MouseDown += new MouseEventHandler(DataGridView_MouseDown);
            //this.DragDrop += new DragEventHandler(DataGridView_DragDrop);
            //this.DragOver += new DragEventHandler(DataGridView_DragOver);
            //this.MouseUp +=new MouseEventHandler(DataGridView_MouseUp);
        }
        void Init ()
        {
            AutoGenerateColumns = false;

            MouseDown += new System.Windows.Forms.MouseEventHandler ( this.OnMouseDown );
            CellDoubleClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellDBClick );
            CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellContentClick );
            CellClick += new System.Windows.Forms.DataGridViewCellEventHandler ( this.OnCellClick );
            ColumnHeaderMouseClick += new DataGridViewCellMouseEventHandler ( OnClickColumnHeader );  //作废。列表排序不在这里实现。而是在 FindList 类中,通过 fl.SortBindingList() 来实现。DataGridView类自身自带了排序功能,只需要传入有排序属性的数据就可以了。
            CellFormatting += new DataGridViewCellFormattingEventHandler(OnCellFormatting); //在显示数据的同时,对Cell里的数据/颜色/字体等进行处理。不必再使用AfterFill()之类的函数了。
            
            ClearContextMenu () ;

            //ListViewColumnSorter sortHelper = new ListViewColumnSorter();
            //Sort( sortHelper );
        }
예제 #7
0
    /// <summary>
    /// 添加一个按钮到DataGridView
    /// </summary>
    /// <param name="grid"></param>
    /// <param name="headerText">按钮标题</param>
    /// <param name="text">默认文本</param>
    /// <param name="callBack">回调</param>
    /// <param name="displayIndex">显示顺序</param>
    /// <param name="UseColumnTextForButtonValue">text参数是否作为按钮文本的值</param>
    public static void AddButtonToDataGridView(ref DataGridView grid, string headerText, string text, DataGridViewCellMouseEventHandler callBack, int displayIndex = 0, bool UseColumnTextForButtonValue = true)
    {
        //删除按钮列
        DataGridViewButtonColumn ButtonCoumn = new DataGridViewButtonColumn();

        ButtonCoumn.HeaderText   = headerText;
        ButtonCoumn.Text         = text;
        ButtonCoumn.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
        ButtonCoumn.DisplayIndex = displayIndex;
        ButtonCoumn.UseColumnTextForButtonValue = UseColumnTextForButtonValue;

        grid.CellMouseUp -= callBack;
        grid.CellMouseUp += callBack;
        grid.Columns.Add(ButtonCoumn);
    }
예제 #8
0
 // permet de subscribe une méthode à l'event
 public void AddClickMethod(DataGridViewCellMouseEventHandler methode)
 {
     dataGridView.CellMouseClick += methode;
 }