本文介绍了从一种形式传递价值,在C#中的另一种形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要通过 ID 从一种形式到另一个在C#。

I have to pass id from one form to another from in C#.

我不能够。做到这一点

C#代码为:

private void btnedit_Click(object sender, EventArgs e)
{
    foreach (DataGridViewRow a in dataGridViewUnPaidList.Rows)
    {
        if (a.Cells[0].Value != null)
        {
            Convert.ToInt64(a.Cells[1].Value); // i have to pass this id in AddInvoice() form
            AddInvoice ad = new AddInvoice();
            ad.Show();
            NonPaideData non = new NonPaideData();
            non.Hide();
        }
        else
        {
        MessageBox.Show("Now Row Is Selected");
        }
    }
}



任何人能告诉我是什么我做错了什么?

Can anybody tell me what I am doing wrong?

推荐答案

在Form1中

private void ShowForm2()
{
    string value = TheTextBox.Text;
    Form2 newForm = new Form2();
    newForm.TheValue = value;
    newForm.ShowDialog();
}

在窗体2

private string _theValue;
public string TheValue
{
    get
    {
        return _theValue;
    }
    set
    {
        _theValue = value;
        // do something with _theValue so that it
        // appears in the UI

    }
}

请参阅此代码,我认为这将帮助你。

See this code i think this will help you.

这篇关于从一种形式传递价值,在C#中的另一种形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-23 11:52