Translate

> > Extented Datagrid, Enter press move next cell

Extented Datagrid, Enter press move next cell

Posted on Wednesday, November 23, 2011 | No Comments


public partial class DatagridControl : DataGridView
    {
       // ContextMenu m_contextmenu = null;
        public DatagridControl() :base()
           
        {
            InitializeComponent();
            this.BackColor = System.Drawing.Color.NavajoWhite;
            this.AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.PeachPuff;
            this.AlternatingRowsDefaultCellStyle.SelectionBackColor = System.Drawing.Color.SandyBrown;
            this.DefaultCellStyle.BackColor = System.Drawing.Color.Honeydew;
            this.DefaultCellStyle.SelectionBackColor = System.Drawing.Color.LightGreen;
           
            this.BackgroundColor = System.Drawing.SystemColors.InactiveCaptionText;
            this.EditMode = DataGridViewEditMode.EditOnEnter;
           
           
           
            //this.RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.Custom;
            //this.RowHeadersWidth = 30;
        }
       
        //[System.Security.Permissions.UIPermission(
        //        System.Security.Permissions.SecurityAction.LinkDemand,
        //        Window = System.Security.Permissions.UIPermissionWindow.AllWindows)]
        //protected override bool ProcessDialogKey(Keys keyData)
        //{
        //    // Extract the key code from the key value.
        //    Keys key = (keyData & Keys.KeyCode);

        //    // Handle the ENTER key as if it were a RIGHT ARROW key.
        //    if (key == Keys.Enter)
        //    {
        //        return this.ProcessRightKey(keyData);
        //    }
        //    return base.ProcessDialogKey(keyData);
        //}

        //[System.Security.Permissions.SecurityPermission(
        //    System.Security.Permissions.SecurityAction.LinkDemand, Flags =
        //    System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
        //protected override bool ProcessDataGridViewKey(KeyEventArgs e)
        //{
        //    // Handle the ENTER key as if it were a RIGHT ARROW key.
        //    if (e.KeyCode == Keys.Enter)
        //    {
        //        return this.ProcessRightKey(e.KeyData);
        //    }
        //    return base.ProcessDataGridViewKey(e);
        //}
        protected override bool ProcessDialogKey(Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                MoveToNextCell();
                return true;
            }
            else
                return base.ProcessDialogKey(keyData);

        }


        public void MoveToNextCell()
        {
            int CurrentColumn, CurrentRow;
            CurrentColumn = this.CurrentCell.ColumnIndex;
            CurrentRow = this.CurrentCell.RowIndex;
            if (CurrentColumn == this.Columns.Count - 1 && CurrentRow != this.Rows.Count - 1)
            {
               
                base.ProcessDataGridViewKey(new KeyEventArgs(Keys.Home));
                base.ProcessDataGridViewKey(new KeyEventArgs(Keys.Down));
            }
            else
                base.ProcessDataGridViewKey(new KeyEventArgs(Keys.Right));

        }
    }

Leave a Reply

Powered by Blogger.