Fiendcoder1 Fiendcoder1 - 9 months ago 51
C# Question

I cant pass my array variable to another form in winform c#

I declared my array like this

string[] dateArray = new string[10];
then placing a value to it like this:

public void btnAdd_Click(object sender, EventArgs e)
dateArray[i] = date.Text.ToString();

So far, after a few inputs and want to check if it the
has a value I did this.

private void button1_Click(object sender, EventArgs e)
string toDisplay = string.Join(Environment.NewLine, dateArray);

And it is really have a value and displaying it.

So I've created a button that may pass the value of
to another form for it to display and print. I'm using iTextSharp. Here is my button:

public static string finalDate;
private void printBtn_Click(object sender, EventArgs e)
string finalDate = string.Join(Environment.NewLine, dateArray);
printForm table_form = new printForm();

And passing the string
(Second form) to here

table2.AddCell(new Phrase(tableITS.finalDate, data));

But no luck, I tried putting a message box at the end of
but it really doesn't have a value


What am I getting wrong?

I'm passing it here

private void printForm_Load(object sender, EventArgs e)
string finalDate2 = tableITS.finalDate;
//Document printing stuff

Answer Source

Assuming that You want to pass data from Form1 to Form2:

Create a public property in Form2like:

public string[] dateArray { get; set;}

and then in your `Form1:

Form2 frm = new Form2();
frm.dateArray = dateArray;

Now you can use the dateArray in Form2