提问人:Nisha Goel 提问时间:7/20/2023 更新时间:7/20/2023 访问量:13
查找哪个 customtextbox 将消息发送到 customdatagridview
Finding which customtextbox sends the message to customdatagridview
问:
我有一个customtextbox和一个customdatagridview。customtextbox 在其 OnKeyDown 事件上的行为为 Tab 键,在其后退键上的行为分别为 reverse Tab 键。现在在我的 customdatagridview 的 OnEnter 上,我想分析哪个 customtextbox 将焦点发送到 customdatagridview,以便我相应地更改我的当前单元格,但我对如何获取它感到困惑。
public partial class betterdatagridview : DataGridView
{
protected override void OnEnter(EventArgs e)
{
// datagridview has data
if (this.RowCount > 0)
{
if () // what to place here to check which customtextbox send me here
{
this.CurrentCell = this.Rows[0].Cells[0]; // select the first cell in the first row
}
else if()
{
this.CurrentCell = this.Rows[RowCount - 1].Cells[0];//[0, this.RowCount - 1]; // select the last row's first cell
}
this.BeginEdit(true); // it must stay here
TextBox textBox = (TextBox)this.EditingControl; // Cast the EditingControl to TextBox
textBox.SelectionStart = textBox.Text.Length; // select the textbox from last
}
下面是 customtextbox
protected override void OnKeyDown(KeyEventArgs e)
{
if (!DisableFeatures)
{
if ((e.KeyCode == Keys.Enter || e.KeyCode == Keys.Down)&& this.Text !="")
{
e.Handled = true;
e.SuppressKeyPress = true;
TriggerEvent?.Invoke(Last, Name);
if (!Last)
{
SendKeys.Send("{TAB}");
}
return;
}
if ((e.KeyCode == Keys.Back || e.KeyCode == Keys.Up) && this.Text.Length == 0)
{
SendKeys.Send("+{TAB}");
}
}
base.OnKeyDown(e);
}
答: 暂无答案
评论