Fiendcoder1 Fiendcoder1 - 8 days ago 7
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
dateArray
has a value I did this.

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


And it is really have a value and displaying it.

So I've created a button that may pass the value of
dateArray
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();
table_form.Show();
}


And passing the string
finalDate
(Second form) to here

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


But no luck, I tried putting a message box at the end of
doc.Close();
but it really doesn't have a value

MessageBox.Show(tableITS.finalDate);


What am I getting wrong?
EDIT:

I'm passing it here

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

Answer

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;
frm.ShowDialog();

Now you can use the dateArray in Form2