Windows froms DataGridView [英] Windows froms DataGridView

查看:79
本文介绍了Windows froms DataGridView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是什么,在Windows窗体应用程序中,我的任务就像我有文本框一样,
其中将填充员工姓名",并且该名称应该已经存在于员工姓名"中.
为此,我采取了一个按钮.当我单击该按钮时,将显示一个弹出窗口.在该窗口中,当我用鼠标单击相应的单元格时,将在datagridview中显示员工详细信息.

但是我的要求是减少鼠标的使用, 我需要使用Enterkey选择相应的单元格.但是EnterKey的默认操作将是当我单击该键时它将移动到下一行单元格.
我想限制Enter键的默认操作,还希望将click事件分配给enterKey来选择相应的单元格,例如mouseclick事件...

我已经尝试过使用表单的KeyPreveiew属性,但是我没有成功....

如果有人知道...该怎么做,请发送给我答案....

What My Question is, in my Windows forms application i have task like i have textbox,
which will filled with Employee Name and that name should be already existin Employee name.
for that i have taken one button. when i click on that button, i display a popup window.In that window i display the employee details in datagridview when i click on the corresponding cell with mouse that popup will be closed.

But what my requirement is to reduce the mouse usage,i need to select the corresponding cell with Enterkey. but EnterKey default action will be when i click the key it will move to next row cell.
i want to restrict the default action of the Enter key and also assign the click event to enterKey to select the corresponding cell as like the mouseclick event...

i have tried it with KeyPreveiew property of the form But i didn''t succeeded....

Please send me the answer if any body knows...what to do....

推荐答案

首先,我认为您打算过分设计-选中单元格后,在按下Enter/Return键时,DataGridView会达到预期的行为.

但这是要使用的代码的草图":
First, I think you are making a mistake by planning to over-ride the expected behavior of the DataGridView when it gets an Enter/Return keypress while a cell is selected.

But here''s a ''sketch'' for code to use:
// this code has not been tested

// if using international fonts this may have
// to be modified to take into account Locale, etc. ? See MSDN.
private char EnterChar = (char)13;

private void dataGridView1_KeyPress(object sender, KeyPressEventArgs e)
{
    // note that 'SelectedCells is never equal to 'null
    if (e.KeyChar == EnterChar && dataGridView1.SelectedCells.Count == 1)
    {
        // close the pop-up code here
        //
        // ignore this keypress
        e.Handled = true;
    }
}


这篇关于Windows froms DataGridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆