TextBox离开事件无法正常工作 [英] TextBox Leave Event Is not working properly
问题描述
我正在为C#中的库存管理创建一个基于窗口的应用程序。在这个应用程序中,我有一个表格 StockEntryMaster ,表格中有 8-9 textBoxes 。在一个文本框上有文本框离开事件被激活,这个事件第一次工作非常正常但下一个项目我再次在该文本框中输入一些值事件将无法按预期工作。实际上文本Leave事件没有被触发。
这里我提供了我的文本框离开事件的代码
I am creating a window based application for stock Management in C#. In this application i have a form StockEntryMaster and there is 8-9 textBoxes in the form. On one textbox there is textbox leave event is activated, for the very first time this event work very fine but next item again i enter some value in that textbox the events won't work as expected. Actually the text Leave event isn't fired.
Here i am providing the code for my textbox leave event
private void txtItemCode_Leave(object sender, EventArgs e)
{
getItemList();
}
和函数getListItem代码的代码低于
and code for function getListItem code is below
public void getItemList()
{
DataTable dt = new ItemGroupOp().getItems(txtItemCode.Text);
if (dt.Rows.Count > 0)
{
txtItemName.Text = dt.Rows[0]["ItemName"].ToString();
txtItemGroup.Text = dt.Rows[0]["ItemGroup"].ToString();
}
else
{
MessageBox.Show("No Item exists for this ItemCode");
}
}
所以请建议我解决方案,以便我可以让我的项目更好,它的工作原理很好。
提前谢谢
So please suggest me the solution so that i can make my project better and it works fine.
Thanks in advance
推荐答案
我认为你错了:每当文本框丢失输入焦点时就会触发Leave事件另一个控件。
我怀疑它看起来没有,因为你的getItemList代码每次都将相同的值设置到其他两个文本框中。
试一试:添加到事件处理程序的顶部:
I think you are wrong: the Leave event is fired every time the textbox loses the input focus to another control.
I suspect that it appears like it doesn't, because your getItemList code sets the same values into the other two textboxes each time.
Try it: Add to the top of the event handler:
Console.WriteLine("Leave");
在调试器中运行应用程序时观察输出窗格。
I离开事件从来没有问题,而且我很确定现在已经发现任何像它不起作用的重大问题了!
And watch the output pane while you run your app in the debugger.
I've never had a problem with the Leave event, and I'm pretty sure that any significant problem like it not working would have been spotted by now!
这篇关于TextBox离开事件无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!