简体   繁体   中英

On a button click, create a new window and display content of an array in C#

I have a main GUI in where I add data, in 12 columns. Each data is on one row as it comes in. This data is pushed into an array which is accessible globally. The array is dynamic 2D, growing each time I enter a set of data.

I wish to have a button that, when pressed, displays all the currently available data held in the array. If I can edit it then it's a step further, but at the moment I just need to be able to view the contents of my array.

My code is long as there are many buttons, listboxes doing different things. If needed, I can mail my code.


public void button1_Click(object sender, EventArgs e) {
    Form2.Fm2 = new Form2();
    Form2.Fm2.listBox1_SelectedIndexChanged();  
    if (Form2.Fm2 == null) {
        Form2.Fm2.Show();
    }
    else {
        Form2.Fm2.Show();
        Form2.Fm2.BringToFront();
    }  
}

In the above, I want to pass values of my 2D array into the Listbox on Form2. Is this the correct methodology or am I missing something?

您可以更改显示窗体的构造函数以采用数组,然后使用它填充一个ListView或另一个适当的控件。

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