简体   繁体   中英

Passing parameter value to a new form

I would like to point to a row. Get the Oid(the parameter I want to pass). When I click a button on the ribbon. It will open MifarePasswordForm. I would like to pass Oid to MifarePasswordForm so that the Oid can be saved in Mifare Card but I'm stuck at getting the Oid. So far, this is what I've got.

public void barButtonItem1_ItemClick()
    {
        staff entity = gridView.GetRow(gridView.GetSelectedRows()[0]) as staff;
        entity.Oid;
        MifarePasswordForm modalForm = new MifarePasswordForm();
        modalForm.ShowDialog();
        RefreshData();
    }

This is my password form.

    public MifarePasswordForm(int _iD)
    {
        InitializeComponent();
        int iD = _iD;
    }

Updated code

      public void barButtonItem1_ItemClick()
    {
        staff entity = gridView.GetRow(gridView.GetSelectedRows()[0]) as staff;

        MifarePasswordForm modalForm = new MifarePasswordForm(entity.Oid);
        modalForm.ShowDialog();
        RefreshData();
    }

public MifarePasswordForm(int _iD)
    {
        InitializeComponent();
        int iD = _iD;
        textBox1.Text += iD;
    }

在此处输入图片说明

What you can do is, pass your parameter to form in the constructor itself OR, make a public property and access it after creating formInstance and assign it your designated value.

eg

MifarePasswordForm modalForm = new MifarePasswordForm(entity.Oid);
    modalForm.ShowDialog();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM