2014-05-22 57 views
-3

我需要幫助使用在C#中更改seatarray。將值從表單傳遞給表單?並刷新從?

我有一個列表框,它的座位數。我認爲價值有所變化,但我沒有看到它可能是因爲我的列表框不刷新?

無論如何重新啓動表單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

是什麼的Test2的定義,是someValue中的方法或控制。你需要明確你正在做什麼。你沒有給我們足夠的信息來回答你的問題。 –

+0

test2是一個char,導致座位數組中的A的內容是char類型。 – user3663038

+0

您需要刪除並重新分配您的seatArray到您的列表框的數據源,以便您的更改被看到。 –

回答

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(); 
    } 
} 
+0

座位數組是靜態的它的座位[] seatArray = new Seats [15]; 而A在seatarray它的一個字符類型。 – user3663038

+0

這就是我所說的,沒有你的實現,我們必須構建我們自己的想法,看看你的代碼是什麼樣的。雖然我說的刪除/重新添加數據源仍然適用 –

+0

您可以編輯靜態代碼嗎? idk if listBox1.DataSource = null; //從你的列表框的DataSource中移除你的seatArray listBox1.DataSource = seatarray; //重新分配它 – user3663038

相關問題