将值从表单传递到表单?并刷新从?

时间:2014-05-22 01:54:46

标签: c# forms

我需要帮助使用C#更换seatarray。

我有一个带有seatarrays的列表框。我认为价值已发生变化,但我不明白这可能是因为我的列表框没有刷新?

无论如何重新启动表单1?

表格1

  private void textBox2_Click(object sender, EventArgs e)//A
            {

                using (Form2 f = new Form2())
                {
                    f.SomeValue = 'T';
                    f.ShowDialog();
                    test2 = f.SomeValue;//test2 is char type variable
                    seatArray[num - 1].A = test2;//seat array A is a char type


                }
            }

表格2

public char SomeValue { get; set; }
        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            SomeValue = 'V';
           // this.Close();
        }

1 个答案:

答案 0 :(得分:0)

我会稍微充实一下我的评论。当您提出问题时,您应该尝试制作您自己解释并能够执行的代码以验证您的问题。我不得不做出一些假设,但我想这里的代码会告诉你我的评论是什么意思。

<强> Form1中

public partial class Form1 : Form
{
    static Seats[] seatArray = new Seats[15];
    char test2;

    public Form1()
    {
        InitializeComponent();
        for (int i = 0; i < seatArray.Length-1; i++)
        {
            Seats tmp = new Seats();
            tmp.A = (char)(65+i);
            seatArray[i] = tmp;
        }

        listBox1.DataSource = seatArray;
    }

    private void textBox2_Click(object sender, EventArgs e)
    {
        using (Form2 f = new Form2())
        {
            f.SomeValue = 'T';
            f.ShowDialog();
            test2 = f.SomeValue;//test2 is char type variable
            seatArray[2].A = test2;//seat array A is a char type
            listBox1.DataSource = null; //remove array from the listbox's datasource
            listBox1.DataSource = seatArray; //reassign it to it.
        }

    }   

}

public class Seats
{
    public char A { get; set; }

    public override string ToString()
    {
        return A.ToString();
    }
}