Devexpress GridView控制Enter键时向下移动

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/Crazy2910/article/details/51957548
        /// <summary>
        /// 控制Enter键时向下移动
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridView1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {

                int rowHandle = gridView1.FocusedRowHandle;
                if (gridView1.FocusedColumn.Caption == null) return;
                string coloumnName = gridView1.FocusedColumn.Caption;
                if (coloumnName.Contains("入仓码"))//指定的列
                {
                    rowHandle = rowHandle + 1;
                    if (rowHandle >= gridView1.RowCount)
                    {
                        if (Convert.ToInt32(coloumnName.Substring(3))*2 >= Convert.ToInt32(spinCol.Text))
                        {
                            SetFocuse(gridView1, 0, coloumnName);
                        }
                        else
                        {
                            SetFocuse(gridView1, 0, coloumnName.Substring(0, 3) + (Convert.ToInt32(coloumnName.Substring(3)) + 1));
                        }

                    }
                    else
                    {
                        SetFocuse(gridView1, rowHandle, coloumnName);
                    }
                }
            }
        }
        /// <summary>
        /// 设置某单元格获得焦点
        /// </summary>
        /// <param name="view"></param>
        /// <param name="rowHandle"></param>
        /// <param name="columnName"></param>
        private void SetFocuse(GridView view, Int32 rowHandle, string columnName)
        {
            view.Focus();
            view.FocusedRowHandle = rowHandle;
            view.FocusedColumn = view.Columns[columnName];
            view.ShowEditor();
        }
展开阅读全文

没有更多推荐了,返回首页