[英]pressing enter key and open a new form in datagridview
When a user presses Enter key in one of my datagridview cells (like in column1 cells), a new form like form2 should be opened.当用户在我的 datagridview 单元格之一(如在 column1 单元格中)按下 Enter 键时,应该打开一个新表单,如 form2。 I know that in the keypress event I should write
e.handled=true;
我知道在
e.handled=true;
事件中我应该写e.handled=true;
to achieve this, but this code is not working when the datagridview cell is active.来实现这一点,但是当 datagridview 单元处于活动状态时,此代码不起作用。 How can I do it?
我该怎么做?
You need to handle the EditingControlShowing
event of DataGridView control and PreviewKeyDown
event of Cell's Control.您需要处理DataGridView 控件的
EditingControlShowing
事件和Cell 控件的PreviewKeyDown
事件。
dataGridView1.EditingControlShowing += (senderObject,eventArgs)=>
{
eventArgs.Control.PreviewKeyDown += (sa, ea) =>
{
if (ea.KeyCode == Keys.Return)
{
MessageBox.Show("Something...");
}
};
};
hello try to use this in below create two form on form1 use the grid on given below name or as you can你好尝试在下面使用这个在form1上创建两个表单使用下面给定名称的网格或者你可以
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
{
testform tf = new testform();
{
if (dataGridView1.CurrentRow.Cells[0].Selected)
{
if (e.KeyCode.ToString() == "F1")
{
tf.Show();
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.