Click here to Skip to main content
11,924,800 members (58,697 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
How To pass multidimensional array from one form to another form?
Posted 11-May-13 1:47am
Raja Soosai 11-May-13 6:54am
In web form or windows form?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:
ufukavci 12-May-13 5:37am
form2 is opened by a button on form1 and when i press a button , i want to send array variables to form2
OriginalGriff 12-May-13 5:42am
Yes. I know.
Did you look at the links at all?
What part of this is giving you a problem?
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

Try this on

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

In form2

public Form2(string[,] arr) // Constructor over loading
        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];

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web04 | 2.8.151125.3 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100