Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I set a value if a method is called from a child form?
    primarykey
    data
    text
    <p>My application currently has 2 forms. It creates a sub form, Form2, which ends with the following code:</p> <pre><code>public partial class Form2 : Form { ... Form1 frm = new Form1(); frm.rglu = glu; frm.rdate = fulldate; frm.sort(); Close(); } </code></pre> <p>Note that form1 is just a couple of buttons at the moment. One starts off Form2 as follows:</p> <pre><code> private void button2_Click(object sender, EventArgs e) { using (Form2 AcqForm = new Form2()) { AcqForm.ShowDialog(this); } } </code></pre> <p>No other code runs except a button <code>test();</code> shown later). This <code>frm.sort();</code> runs the following code found in Form1:</p> <pre><code>public partial class Form1 : Form { public void sort() { datelist = new List&lt;DateTime&gt;(rdate); datelist.Sort((a, b) =&gt; a.CompareTo(b)); var result = rdate .Select((d, i) =&gt; new { Date = d, Int = rglu[i] }) .OrderBy(o =&gt; o.Date) .ToArray(); this.rdate = result.Select(o =&gt; o.Date).ToArray(); this.rglu = result.Select(o =&gt; o.Int).ToArray(); //all works fine for (int i = 7; i+7 &lt;= rglu.Length; i++) { Console.WriteLine(Convert.ToString(rdate[i]) + Convert.ToString(rglu[i])); } //This shows values as expected } } </code></pre> <p>However when I set a button to run some more code using <code>rglu</code> and <code>rdate</code> the I get null pointer errors:</p> <pre><code>public partial class Form1 : Form { private void test(object sender, EventArgs e) { for (int i = 7; i &lt; rglu.Length; i++){} //rglu is null! The values are lost. } } </code></pre> <p>I believe the solution requires a <code>int[] rglu {get; set;}</code> method. However so far I have been unsuccessful in using these things at all. Has anyone encountered this problem?</p> <p>Edit: rglu is defined like this:</p> <pre><code>public int[] rglu { get; set; } //I don't get how this works though </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload