我看了这个文章
http://blog.csdn.net/KJ_Wang/archive/2006/11/16/1388766.aspx
照着弄了个测试的,就是无法编译,请各位大大帮忙看看哦
错误是
未将对象引用设置到对象的实例。
我看了这个文章
http://blog.csdn.net/KJ_Wang/archive/2006/11/16/1388766.aspx
照着弄了个测试的,就是无法编译,请各位大大帮忙看看哦
错误是
未将对象引用设置到对象的实例。
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)))
...{
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);
}
}
}