Winform中的DataGridView控件内容自动保存
欣野吧
全部回复
仅看楼主
level 8
欣野 楼主
2010年12月22日 02点12分 1
level 8
欣野 楼主
DatagridView中验证数据错误后仍把焦点定在该单元格
http://jeffsonglove.blog.sohu.com/83683437.html
2010年12月22日 06点12分 2
level 8
欣野 楼主
2010年12月22日 07点12分 3
level 8
欣野 楼主
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
    public class CustomDataGridView : DataGridView
    {
        protected override bool ProcessDialogKey(Keys keyData)
        {
            Keys key = (keyData & Keys.KeyCode);
            if (key == Keys.Enter)
            {
                return this.ProcessRightKey(keyData);
            }
            return base.ProcessDialogKey(keyData);
        }
        public new bool ProcessRightKey(Keys keyData)
        {
            Keys key = (keyData & Keys.KeyCode);
            if (key == Keys.Enter)
            {
                //第一种情况:只有一行,且当光标移到最后一列时
                if ((base.CurrentCell.ColumnIndex == (base.ColumnCount - 1)) && (base.RowCount == 1))
                {
                    base.CurrentCell = base.Rows[base.RowCount - 1].Cells[0];
                    return true;
                }
                //第二种情况:有多行,且当光标移到最后一列时,移到下一行第一个单元
                if ((base.CurrentCell.ColumnIndex == (base.ColumnCount - 1)) && (base.CurrentCell.RowIndex < (base.RowCount - 1)))

2010年12月22日 07点12分 4
level 8
欣野 楼主
                {
                    base.CurrentCell = base.Rows[base.CurrentCell.RowIndex + 1].Cells[0];
                    return true;
                }
                return base.ProcessRightKey(keyData);
            }
            return base.ProcessRightKey(keyData);
        }
 
        protected override bool ProcessDataGridViewKey(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                return this.ProcessRightKey(e.KeyData);
            }
            //if (e.KeyCode == Keys.F4)
            //{
            //    return this.ProcessRightKey(e.KeyData);
            //}
            return base.ProcessDataGridViewKey(e);
        }
    }
}
2010年12月22日 07点12分 5
1