English 中文(简体)
在网格视图最后一行使用 ENTER 键结束单元格编辑
原标题:Trying to end editing of cell while on the last row of a gridview using the ENTER key

我在 WinForm 中有一个网格视图 。 我有一个要编辑的网格视图列。 我可以点击一个单元格编辑, 并点击输入以完成每个单元格的编辑, 除了最后一行中的单元格。 “ 输入” 键在下面没有行可以更改时不起作用 。 我试图使用 _ keyPress 和 _ keyDown 事件来将“ 输入” 键更改为标签, 使用户能够以正常的方式编辑并点击输入以提交更改 。

如果有任何人有意见,我将不胜感激。

目前,当我选择一个单元格时,它会进入编辑模式,而当单元格不再被选中时,我打电话给我的结尾事件并提交任何修改。

我试图添加一个编辑控制显示( Event), 下面的代码是试图将事件指派给正在编辑的控制, 希望它会调用按键。 但是它仍然没有这样做 。

private void dg_EditingControlSHowing(object sender,DataGridViewEditingControlShowingEventArgs e)
{
e.Control.KeyDown += new KeyEventHandler(Control_KeyDown);
}                                                              
private void Control_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData == Keys.Enter)
{
 this.ProcessTabKey(true);
}
}
问题回答
if(e.KeyData == Keys.Enter)
{
this.ProcessTabKey(true);
  if(datagrid1.Rows[grid.Rows.Count - 1].Selected == true){
    //run your event here
  }
}

这是关于我唯一能想到的东西。 它会检查您最后一行是否被选中, 这样它就可以进入另一个进程, 比如说, 当它碰到那个点时, 您可以把它添加一个新行 。

我不百分之百确定你需要什么 但我希望它能帮助你 一种方法或给你一个想法





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签