2014-12-30 17 views
-1

當我嘗試在c#中爲DataGridview創建KeyDown事件時,它顯示錯誤「handler Control_KeyDown already exists in this class」。如何在同一窗口窗體中以編程方式爲多個DataGridview創建'KeyDown'事件?

我已經在DataGridview1_EditingControlShowing事件中爲DataGridview1創建了KeyDown事件。

e.Control.KeyDown +=new KeyEventHandler(Control_KeyDown); 

我想創建DataGridview2同一事件,所以在DataGridview2_EditingControlShowing事件

e.Control.KeyDown +=new KeyEventHandler(Control_KeyDown); // here the above error shown.So i tried 

DataGridview2.KeyPress +=new KeyEventHandler(Control_KeyDown); // it compiles, but event not firing. 

回答

1

,如果你想處理keypress事件事件處理程序可能是KeyPressEventArgs 和​​事件處理程序應該是PreviewKeyDownEventArgs

例如

dataGirdView1.KeyPress += OnDataGirdView1_KeyPress; 

private void OnDataGirdView1_KeyPress(object sender, KeyPressEventArgs e) 
    { 

    } 

關鍵按下事件

dataGirdView1.PreviewKeyDown += dataGridView1_PreviewKeyDown; 


private void dataGridView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) 
    { 

    } 
+0

了「的keydown」或「按鍵」是不是在第二gridview的射擊 – Prathap

相關問題