1
我正在开发一个windows form
,其中包含两个控件Textbox
和Datagridview
。向下和向上箭头键不滚动DataGridView中的当前单元格
现在,当我第一次打开窗体焦点应该在文本框,如果我输入的东西它应该被附加到文本框。
如果我按UP/Down arrow key
重点应在DataGridview
和Highlight
应该移动到下一行。
但问题是它只将焦点设置为gridview
但不选择下一行。它滚动down/UP on next key press
。如果注意力集中在GridView
和if I start typing alphabets it should be appended to TextBox text
上,它也是一样,但这里它也只将焦点设置为textbox
,而在另一按键上它开始在其中输入文本。
如何实现这个?我现在用
代码是:
if (e.KeyCode== Keys.Down)
{
this.DgAppDetails.Focus();
int index = DgAppDetails.CurrentCell.RowIndex;
if (index != DgAppDetails.Rows.Count - 1)
{
if (i == 0)
{
DgAppDetails.CurrentCell = DgAppDetails.Rows[index+1].Cells[0];
i++;
}
}
}
else if(e.KeyCode==Keys.Up)
{
this.DgAppDetails.Focus();
int index = DgAppDetails.CurrentCell.RowIndex;
if (index != 0)
{
if (i == 0)
{
DgAppDetails.CurrentCell = DgAppDetails.Rows[index - 1].Cells[0];
i++;
}
}
}
你有代码的例子..?你也设置像'control.Focus()?[MSDN Control.Focus()方法](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.focus .aspx)你在DataGridView中输入什么事件..? – MethodMan