Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7431713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:20:19+00:00 2026-05-29T09:20:19+00:00

My application currently has 2 forms. It creates a sub form, Form2, which ends

  • 0

My application currently has 2 forms. It creates a sub form, Form2, which ends with the following code:

public partial class Form2 : Form
{ ...
    Form1 frm = new Form1();
        frm.rglu = glu;
        frm.rdate = fulldate;
        frm.sort();
    Close();
}

Note that form1 is just a couple of buttons at the moment. One starts off Form2 as follows:

    private void button2_Click(object sender, EventArgs e)
    {
        using (Form2 AcqForm = new Form2())
        {
            AcqForm.ShowDialog(this);
        }
    }

No other code runs except a button test(); shown later).
This frm.sort(); runs the following code found in Form1:

public partial class Form1 : Form
{
    public void sort() 
    {           
        datelist = new List<DateTime>(rdate);
        datelist.Sort((a, b) => a.CompareTo(b));

        var result = rdate
        .Select((d, i) => new { Date = d, Int = rglu[i] }) 
        .OrderBy(o => o.Date) 
        .ToArray();

        this.rdate = result.Select(o => o.Date).ToArray();
        this.rglu = result.Select(o => o.Int).ToArray();  //all works fine

        for (int i = 7; i+7 <= rglu.Length; i++)
        {
    Console.WriteLine(Convert.ToString(rdate[i]) + Convert.ToString(rglu[i]));
        } //This shows values as expected
    }
}

However when I set a button to run some more code using rglu and rdate the I get null pointer errors:

public partial class Form1 : Form
{ 
    private void test(object sender, EventArgs e)
    {
        for (int i = 7; i < rglu.Length; i++){} //rglu is null! The values are lost.
    }
}

I believe the solution requires a int[] rglu {get; set;} method. However so far I have been unsuccessful in using these things at all. Has anyone encountered this problem?

Edit:
rglu is defined like this:

public int[] rglu { get; set; } //I don't get how this works though
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T09:20:20+00:00Added an answer on May 29, 2026 at 9:20 am

    Problem is in form2,
    You mustn’t write ‘Form1 frm = new Form1();’ this code.

    in Form1 wite code like this:

    using System;
    using System.Collections.Generic;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            public int rglu;
            public DateTime rdate;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btnShowForm2_Click(object sender, EventArgs e)
            {
                Form2 frm2=new Form2();
                frm2.Form1Instance = this;
                frm2.Show();
            }
            public void sort()
            {
                datelist = new List<DateTime>(rdate);
                datelist.Sort((a, b) => a.CompareTo(b));
    
                var result = rdate
                .Select((d, i) => new { Date = d, Int = rglu[i] })
                .OrderBy(o => o.Date) // Sort by whatever field you want
                .ToArray();
    
                this.rdate = result.Select(o => o.Date).ToArray();
                this.rglu = result.Select(o => o.Int).ToArray();  //all works fine
    
                for (int i = 7; i + 7 <= rglu.Length; i++)
                {
                    Console.WriteLine(Convert.ToString(rdate[i]) + Convert.ToString(rglu[i]));
                } //This returns values as expected
            }
        }
    }
    

    in Form2 write codes like this:

    using System;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication2
    {
        public partial class Form2 : Form
        {
            public Form1 Form1Instance;
            public Form2()
            {
                InitializeComponent();
            }
    
            private void btnSortValues_Click(object sender, EventArgs e)
            {
                Form1Instance.rglu = glu;
                Form1Instance.rdate = fulldate;
                Form1Instance.sort();
                Close();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a web application. I was just wondering which has
Windows Forms, .net 2.0 My main application thread has a form (A). I have
I am currently creating a class to handle all my form data which will
I am developing an application that currently has a View Controller (call it ViewControllerX).
I'm working on a PyGTK/glade application that currently has 16 windows/dialogs and is about
An application currently in development has the requirements for using MS Word to perform
The application my team is currently developing has a DLL that is used to
I'm currently working in an application that has to navigate a webpage and recollect
I am currently writing an application where the user has, at some point, to
I am currently working on an application that has different permissions/users for the local

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.