Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

C#
private void txtItemCode_Leave(object sender, EventArgs e)
        {
            getItemList();

        }


and code for function getListItem code is below

C#
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
Posted

1 solution

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:
C#
Console.WriteLine("Leave");

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!
 
Share this answer
 
Comments
Member 10276989 8-Sep-14 3:31am    
I have Tried and seen second time leave event isn't firing as it is not displaying the message.

MessageBox.Show("leave");
So what should i do to get control in focus again? @OriginalGriff
OriginalGriff 8-Sep-14 3:40am    
Put the cursor back into it.

And if it isn't displaying the message via the MessageBox, that's probably because there are rows in the table...
Member 10276989 8-Sep-14 3:52am    
I did that, but it showing me an exception for second time that No item exists for that item code. but actually item exists for that code
OriginalGriff 8-Sep-14 3:53am    
And what do you get in the debugger?
Member 10276989 8-Sep-14 4:00am    
No row exists for specified item code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900