我使用代碼datagrid1.controls.add(frmnew)
將表單添加到datagridview。問題在於,那種形式的控件的按鍵事件不會觸發。請給我一個解決方案。Key Press Event
0
A
回答
0
如果你正在使用Windows窗體:
檢查您了.Designer.cs文件,您有一個事件處理程序。
的事件處理程序是這樣的:
this.datagrid1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.datagrid1_KeyPress);
0
如果你想捕捉的DataGridView控件內部的按鍵事件,那麼你必須連接起來的情況下EditingControlShowing。以下是捕獲keypress事件的示例,並且只允許將數字數據輸入到datagridview單元格中。
/// <summary>
/// Occurs when a control for editing a cell is showing
/// </summary>
/// <remarks>Capture key press to handle key entry in datagridview</remarks>
/// <param name="sender"></param>
/// <param name="e"></param>
private void dgDCAL_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
dgDCAL.EditingControl.KeyPress -= EditingControl_KeyPress;
dgDCAL.EditingControl.KeyPress += EditingControl_KeyPress;
}
/// <summary>
/// Handle datagridview cell keypress event
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void EditingControl_KeyPress(object sender, KeyPressEventArgs e)
{
// Only allow 0-9, backspace, period and return key
if (!Char.IsNumber(e.KeyChar) &&
(int)e.KeyChar != 8 &&
(int)e.KeyChar != 46 &&
(int)e.KeyChar != 13) e.Handled = true;
}
相關問題
- 1. Key press not triggering KeyboardEvent
- 2. Javascript:Block form Enter on Key press
- 3. AS3:Key Press點擊塔樓
- 4. Onclick event + Enter key
- 5. 文檔級別的JavaScript Key Press
- 6. textarea maxlength does not work on enter key press
- 7. Textbox Enter Key event not in WPF
- 8. Android Long Press
- 9. Letter Press Effect
- 10. e.keyCode 13(enter key)and keypress event to update basket sometimes not working
- 11. Angular JS Long Press事件
- 12. yii filter without press tab/enter
- 13. FeedWord Press - 媒體附件
- 14. d3.event vs d3.Event
- 15. jquery fullcalendar drop non event on event
- 16. Esper:event_batch unsing timestamp event of event-POJO
- 17. Click Event Event For Cross Page PostBack
- 18. MySQL KEY/UNIQUE KEY
- 19. MessageBox.Show not raising HelpRequested event
- 20. Auto Key vs Set Key
- 21. Mystery Key Value Coding Key
- 22. Terminal MacOS - terminal and「Press [c] to configure」
- 23. R中的PLS:提取PRESS統計值
- 24. 計算PRESS統計/預測Rsquared C#
- 25. createEvent('Event');
- 26. event mediaElement
- 27. Event TableFixHeader
- 28. ControlLoaded event
- 29. OnSubmitted event
- 30. jQuery.fn.autoResize和Return Key
請在此問題上添加正確的標籤。 DataGridView是System.Windows.Forms命名空間中的.Net控件。這不是你在說什麼,所以請刪除該標籤。請爲平臺和語言添加標籤。這是.Net嗎?網?你在談論System.Web.UI.WebControls.DataGrid嗎? System.Windows.Controls.DataGrid?其他一些語言? – 2012-02-20 21:38:36
向表單添加網格很有意義。將表單添加到網格非常模糊,需要代碼片段。 – 2012-02-22 12:37:42