Click here to Skip to main content
15,916,842 members
Home / Discussions / C#
   

C#

 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 1:33
professionalDaveyM696-Jul-08 1:33 
GeneralRe: MDI Parent and Child [modified] Pin
benjamin yap6-Jul-08 1:38
benjamin yap6-Jul-08 1:38 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 1:59
professionalDaveyM696-Jul-08 1:59 
GeneralRe: MDI Parent and Child Pin
benjamin yap6-Jul-08 2:07
benjamin yap6-Jul-08 2:07 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 2:18
professionalDaveyM696-Jul-08 2:18 
GeneralRe: MDI Parent and Child [modified] Pin
DaveyM696-Jul-08 4:16
professionalDaveyM696-Jul-08 4:16 
GeneralRe: MDI Parent and Child [modified] Pin
benjamin yap6-Jul-08 4:48
benjamin yap6-Jul-08 4:48 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 5:45
professionalDaveyM696-Jul-08 5:45 
benjamin yap wrote:
why cant i just cast it to mainform then get the staffTable from there? thought it should work?

Casting will create a new instance so you won't be able to access the original.

Options:
1. Send the hashtable to the other form in FrmLogin constructor so it can be modified.
2. Send the FrmMain to FrmLogin in FrmLogin constructor so all objects of the FrmMain object instance can be accessed/modified - similar to number 1.
3. Make FrmLogin raise an event - preferred.

I've based this on your code as requested but it doesn't exactly make sense this way as I couldn't properly figure out your code flow - a staff member is added to the staff table in the FrmLogin contructor??? Anyway... here is a working sample. Again I've added a button to the frmLogin and the hardcoded staff is added there. Staff class remains unchanged.
FrmMain:
namespace EBMS
{
    public partial class FrmMain : Form
    {
        public Hashtable staffTable;
        public FrmMain()
        {
            InitializeComponent();
            staffTable = new Hashtable();
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            FrmLogin childLogin = new FrmLogin();
            childLogin.StaffChange += new OnStaffChange(childLogin_StaffChange);
            childLogin.ShowDialog(this);
            childLogin.Dispose();
        }

        void childLogin_StaffChange(object sender, StaffChangeEventArgs e)
        {
            staffTable.Add(e.Staff.NRIC, e.Staff);
            MessageBox.Show("Added " + e.Staff.NRIC + " to table.");
        }
    }
}

FrmLogin:
namespace EBMS
{
    public delegate void OnStaffChange(object sender, StaffChangeEventArgs e);
    public partial class FrmLogin : Form
    {
        public event OnStaffChange StaffChange;
        public FrmLogin()
        {
            InitializeComponent();
        }
        private void FireStaffChange(Staff staff)
        {
            if (StaffChange != null)
            {
                StaffChange(this, new StaffChangeEventArgs(staff));
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Staff staff = new Staff(
                "Admin",
                "S123456I",
                "pass123",
                "13 April 1988",
                "address",
                12345678,
                12346567,
                true,
                true,
                false,
                true);
            FireStaffChange(staff);
            Close();
        }
    }
}

StaffChangeEventArgs:
namespace EBMS
{
    public class StaffChangeEventArgs : EventArgs
    {
        private Staff m_Staff;
        public Staff Staff
        {
            get { return m_Staff; }
            set { m_Staff = value; }
        }
        public StaffChangeEventArgs(Staff staff)
        {
            m_Staff = staff;
        }
    }
}


Dave

GeneralRe: MDI Parent and Child [modified] Pin
benjamin yap6-Jul-08 6:00
benjamin yap6-Jul-08 6:00 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 8:12
professionalDaveyM696-Jul-08 8:12 
GeneralRe: MDI Parent and Child Pin
DaveyM696-Jul-08 9:22
professionalDaveyM696-Jul-08 9:22 
GeneralRe: MDI Parent and Child Pin
benjamin yap6-Jul-08 15:30
benjamin yap6-Jul-08 15:30 
GeneralRe: MDI Parent and Child Pin
DaveyM697-Jul-08 11:29
professionalDaveyM697-Jul-08 11:29 
GeneralRe: MDI Parent and Child Pin
benjamin yap7-Jul-08 22:35
benjamin yap7-Jul-08 22:35 
QuestionBound combobox problem Pin
Alessandra775-Jul-08 4:38
Alessandra775-Jul-08 4:38 
QuestionHow to get a RGB values from an image buffer? Pin
CopperCircle5-Jul-08 2:58
CopperCircle5-Jul-08 2:58 
AnswerRe: How to get a RGB values from an image buffer? Pin
User 66585-Jul-08 3:07
User 66585-Jul-08 3:07 
AnswerRe: How to get a RGB values from an image buffer? Pin
Guffa5-Jul-08 5:47
Guffa5-Jul-08 5:47 
QuestionCreating DataView filter ... Pin
Jammer5-Jul-08 2:52
Jammer5-Jul-08 2:52 
Questionsetup problem for windows application Pin
K V Sekhar5-Jul-08 1:51
K V Sekhar5-Jul-08 1:51 
AnswerRe: setup problem for windows application Pin
Christian Graus5-Jul-08 2:04
protectorChristian Graus5-Jul-08 2:04 
GeneralRe: setup problem for windows application Pin
K V Sekhar6-Jul-08 21:28
K V Sekhar6-Jul-08 21:28 
Questionhow to change NumberDecimalSeparator ? Pin
Xmen Real 5-Jul-08 1:41
professional Xmen Real 5-Jul-08 1:41 
AnswerRe: how to change NumberDecimalSeparator ? Pin
DaveyM695-Jul-08 1:52
professionalDaveyM695-Jul-08 1:52 
GeneralRe: how to change NumberDecimalSeparator ? Pin
Xmen Real 5-Jul-08 2:33
professional Xmen Real 5-Jul-08 2:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.