Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Helle theren i want to send data sotred in array from a from to another form but i didn't find a solution.
i can just send 1 data from a form to another

this is my code
C#
// form1

 private void Button1_Click_1(object sender, EventArgs e)
        {
int data= 15;

  Form2 xfrm = new Form1(data);
 xfrm.Show();

}

//form2
public Form5_1_5(int d)
        {
            InitializeComponent();

textbox1.text=d.tostring();

}


me i want to send an array for example
int[] data= new data[1000]

and in form 2 i can see all the data stored in that array
plese help

What I have tried:

// form1

private void Button1_Click_1(object sender, EventArgs e)
{
int data= 15;

Form2 xfrm = new Form1(data);
xfrm.Show();

}

//form2
public Form5_1_5(int d)
{
InitializeComponent();

textbox1.text=d.tostring();

}
Posted
Updated 26-May-16 0:19am

Create a property in Form2
C#
public partial class Form2 : Form
  {
      public int[] MyArray { get; set; }

      public Form2()
      {
          InitializeComponent();
      }


Assign the value to the property of Form2 before calling show()
C#
int[] data = new int[1000];
           Form2 obj = new Form2();
           obj.MyArray = data;
           obj.Show();

and you can access those values in the Form_Load event
 
Share this answer
 
Comments
Jammes_Ca 26-May-16 7:46am    
hi thanks for teh replay, but i have error

in my form 1 i did this

int[] data = new int[1000];
Form2 obj = new Form2();
obj.MyArray = data;
obj.Show();

in form 2 i did this

public int[] MyArray { get; set; }

public Form2()
{
InitializeComponent();
}

}

i get this error
Form1' does not contain a definition for 'MyArray' and no extension method 'MyArray' accepting a first argument of type Form2' could be found (are you missing a using directive or an assembly reference?)

how do i resolve that please
Karthik_Mahalingam 26-May-16 7:51am    
paste the code [ public int[] MyArray { get; set; } ] in Form2
the error message shows that 'Form1'
Karthik_Mahalingam 26-May-16 8:01am    
post your Form1.cs code and Form2.cs code..
Jammes_Ca 26-May-16 8:09am    
i have other question please :)
i have a .ini file that contaon some data.
could you tell me how do i to check if a specefic name existe in this file .ini ??

in my ini file i have the word "cat" for exemple how do i to check the word cat existe in my ini file ??
Karthik_Mahalingam 26-May-16 8:13am    
check these it will help you.
c# - Reading/writing an INI file - Stack Overflow[^]
Read/Write settings to INI File using C#[^]
c# - Reading/writing an INI file - Stack Overflow[^]

if the above links didn't help, post a new question about it, people who are aware of it will respond quicker..
Yes, but exactly how depends on the "relationship" between the forms.
The form that creates an instance of another:
C#
MyForm mf = new MyForm();
mf.Show();
Is the "parent", the other form is the "child".
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
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