ms access afterupdate event in c# textbox
-
I'm unable to get ms access afterupdate event like functionality in c# textbox. What I have done so far is:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData.Equals(Keys.Enter)) MoveToSpecificVocNo(); }
and Leave eventprivate void VocNoTextBox_Leave(object sender, EventArgs e) { MoveToSpecificVocNo(); }
But the problem is If I press enter and press tab to move to next field. The event is called twice. One for Enter key, another for Leave. Is there any solution? Regards Asif Rehman -
I'm unable to get ms access afterupdate event like functionality in c# textbox. What I have done so far is:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData.Equals(Keys.Enter)) MoveToSpecificVocNo(); }
and Leave eventprivate void VocNoTextBox_Leave(object sender, EventArgs e) { MoveToSpecificVocNo(); }
But the problem is If I press enter and press tab to move to next field. The event is called twice. One for Enter key, another for Leave. Is there any solution? Regards Asif RehmanOne way would be using a flag to indicate it had been run already. At the form level:
private bool func_called = false;
In KeyDown you set it to true after calling the function:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.Equals(Keys.Enter))
{
MoveToSpecificVocNo();
func_called = true; // <---
}
}And in Leave you reset it (if this is appropriate for what it does):
private void VocNoTextBox_Leave(object sender, EventArgs e)
{
if ( !func_called )
{
MoveToSpecificVocNo();
}func_called = false; //<---
}Jack of all trades ~ Master of none.
-
I'm unable to get ms access afterupdate event like functionality in c# textbox. What I have done so far is:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData.Equals(Keys.Enter)) MoveToSpecificVocNo(); }
and Leave eventprivate void VocNoTextBox_Leave(object sender, EventArgs e) { MoveToSpecificVocNo(); }
But the problem is If I press enter and press tab to move to next field. The event is called twice. One for Enter key, another for Leave. Is there any solution? Regards Asif RehmanPossibly a better way (depends on what MoveToSpecificVocNo() does) is to implement the SendKeys class:
private void VocNoTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyData.Equals(Keys.Enter))
{
SendKeys.Send ( "\t" );
}
}This will cause the focus to jump and trigger the Leave event.
Jack of all trades ~ Master of none.