Click here to Skip to main content
Rate this: bad
good
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
Comments
Raja Soosai at 11-May-13 6:54am
   
In web form or windows form?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Maciej Los at 11-May-13 7:17am
   
Short and to the point!
ufukavci at 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 at 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 at 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 at 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 at 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 at 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
good
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);
            frm2.Show();
        }
 
In form2
 
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];
        }
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
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