Click here to Skip to main content
15,884,883 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How To pass multidimensional array from one form to another form?
Posted
Comments
Raja Soosai 11-May-13 6:54am    
In web form or windows form?

 
Share this answer
 
Comments
Maciej Los 11-May-13 7:17am    
Short and to the point!
ufukavci 11-May-13 8:51am    
i just have 2 forms ,, on form1 i take variables from a file and initialize them in an multidimensional array ,, i want to pass this array to other form2 when i press a button
OriginalGriff 11-May-13 9:45am    
So Form2 is opened from Form1? In which case Form1 is the Parent, and Form2 is the Child. Use a property or constructor as described in Part 1 above.
Maciej Los 11-May-13 9:48am    
Please, carefully read articles. If it's possible to pass one argument, there is possibility to pass many arguments (array of arguments).
OriginalGriff 11-May-13 10:12am    
Sorry, yes, good point. I should have mentioned that - I tend to forget that beginners may not realize that an array of objects is just an object itself... :laugh:
Try this on

In form1
C#
private void button1_Click(object sender, EventArgs e)
        {
            string[,] arr = { {"One","two","three"},{"red", "blue","green"}};
            Form2 frm2 = new Form2(arr);
            frm2.Show();
        }


In form2

C#
public Form2(string[,] arr) // Constructor over loading
        {

            InitializeComponent();
            Array.Copy(arr,array1,arr.Length);

        }

        private void Form2_Load(object sender, EventArgs e)
        {
            label1.Text = array1[0, 0];
            label1.Text +="\n"+ array1[0, 1];
            label1.Text += "\n" + array1[0, 2];
            label1.Text += "\n" + array1[0, 3];
            label1.Text += "\n" + array1[0, 4];
            label1.Text += "\n" + array1[0, 5];
        }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900