/* By samqty * * this file contains an extended version of the the datagrid view * it enables the horzontal movement of the focus when a user is entering data * */ using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace ZeeUIUtility { //the class defination that inherits from DataGridView public class DataGridViewEx : DataGridView { public DataGridViewEx() : base() { //set the edit mode to "on enter" so that when a cell gains focus //it automatically enters editing mode this.EditMode = DataGridViewEditMode.EditOnEnter; } protected override bool ProcessDialogKey(Keys keyData) { //if the key pressed is "return" then tell the datagridview to move to the next cell if (keyData == Keys.Enter) { MoveToNextCell(); return true; } else return base.ProcessDialogKey(keyData); } /// /// this function moves the focus to the next cell /// public void MoveToNextCell() { int CurrentColumn, CurrentRow; //get the current indicies of the cell CurrentColumn = this.CurrentCell.ColumnIndex; CurrentRow = this.CurrentCell.RowIndex; //if cell is at the end move it to the first cell of the next row //other with move it to the next cell 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)); } } }