.NET下keydown事件,默认情况是可直接触发的:如在Spread内key按下的时候。然而,在Edit模式下---用户在单元格内输入文字过程,KeyDown事件是不被触发的。 这样的话,如果要实现KeyDown,则需要“特殊”设置才可触发KeyDown事件,参考代码如下:
1: private void InitKeyDown()
2: {
3:
4: fpSpread1.EditModePermanent = true;
5:
6: fpSpread1.EditModeReplace = true;
7:
8: fpSpread1.EditMode = true;
9:
10:
11:
12: fpSpread1.EditModeOn +=fpSpread1_EditModeOn;
13:
14: fpSpread1.EditModeOff +=fpSpread1_EditModeOff;
15:
16: }
17:
18:
19:
20: private void fpSpread1_KeyDown(object sender, KeyEventArgs e)
21:
22: {
23:
24: }
25:
26:
27:
28: private void fpSpread1_EditModeOn(object sender, System.EventArgs e)
29:
30: {
31:
32: KeyEventHandler keyDown = new KeyEventHandler(fpSpread1_KeyDown);
33:
34: fpSpread1.EditingControl.KeyDown += keyDown;
35:
36: }
37:
38:
39:
40: private void fpSpread1_EditModeOff(object sender, System.EventArgs e)
41:
42: {
43:
44: KeyEventHandler keyDown = new KeyEventHandler(fpSpread1_KeyDown);
45:
46: fpSpread1.EditingControl.KeyDown -= keyDown;
47:
48: }
49:
50:
需要特别注意的是:InitKeyDown()方法,在构造函数执行完InitializeComponent()调用。