Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..

I am developing a billing software,Using MDIchild forms for entering new bills. Having problem to increment the bill number in run time when more than one bill is opened.If the first bill value is entered, then the second bill number must be incremented in run time itself while changing the tab . In tab change event i am not able access the bill no in chidform to check and increment. Can anyone help me pls..

[edit]SHOUTING removed - OriginalGriff[/edit]
Posted
Updated 7-May-12 5:06am
v4
Comments
OriginalGriff 6-May-12 5:48am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.
Shahin Khorshidnia 6-May-12 5:52am    
Not to hard, what did you do and what was the problem?

1 solution

You could register your currently opened bill child windows and unregister them when closing.

When the bill number in one window is changed you iterate through your single child window instances and set the new bill number according to the new entered one.

The most simple way to achieve the register/unregister mechanism would be a static class that holds a list with the window instances.

Possible solution:

Add a method SetNumber to your ChildForm, which sets the number in the bill number text box.
C#
public void SetNumber(int number)
{
    textBoxBillNo.Text = number.ToString();
}


Create a class called MdiHandler.
C#
public class MdiHandler
{
    private static List<ChildForm> mdiChilds = new List<ChildForm>();

    public static void Register(ChildForm child)
    {
        if (!mdiChilds.Contains(child))
            mdiChilds.Add(child);
    }

    public static void Unregister(ChildForm child)
    {
        if (mdiChilds.Contains(child))
            mdiChilds.Remove(child);
    }

    public static void UpdateChilds(ChildForm child, int start)
    {
        int i = start;

        foreach (ChildForm frm in mdiChilds)
            if (frm != child)
                frm.SetNumber(++i);
    }
}


When creating a ChildForm object put in its Load event:
C#
MdiHandler.Register(this);


To the KeyPress event of your bill number text box add the following code:
C#
private void textBoxBillNo_KeyPress(object sender, KeyPressEventArgs e)
{
    if ((e.KeyChar >= '0') && (e.KeyChar <= '9'))
        MdiHandler.UpdateChilds(this, int.Parse(textBox1.Text + e.KeyChar));
}


I hope that is what you want to achieve and helps you.
 
Share this answer
 
v2
Comments
godwinrk 7-May-12 11:09am    
Thank u vry mch for the code. But how to implement it in tab change?? While changing the tab , i need to check and increment both the tab number and bill number in corresponding childform....
HiDensity 7-May-12 12:32pm    
Well, the bill number is updated immediately when it is changed in the text box.
I did not mention, you want it to be done on changing the window.

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