Click here to Skip to main content
15,891,136 members
Home / Discussions / C#
   

C#

 
GeneralRe: LINQ to Entities Pin
PIEBALDconsult15-Feb-11 10:21
mvePIEBALDconsult15-Feb-11 10:21 
GeneralRe: LINQ to Entities Pin
OriginalGriff15-Feb-11 21:18
mveOriginalGriff15-Feb-11 21:18 
GeneralRe: LINQ to Entities Pin
PIEBALDconsult16-Feb-11 1:40
mvePIEBALDconsult16-Feb-11 1:40 
GeneralRe: LINQ to Entities Pin
OriginalGriff16-Feb-11 2:23
mveOriginalGriff16-Feb-11 2:23 
GeneralRe: LINQ to Entities Pin
PIEBALDconsult16-Feb-11 13:23
mvePIEBALDconsult16-Feb-11 13:23 
GeneralRe: LINQ to Entities Pin
OriginalGriff16-Feb-11 22:17
mveOriginalGriff16-Feb-11 22:17 
AnswerRe: LINQ to Entities Pin
Not Active15-Feb-11 10:07
mentorNot Active15-Feb-11 10:07 
QuestionSingleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 4:36
Edunt15-Feb-11 4:36 
Hello - need some help please....

I am using Visual Studio 2010, and have created a "simple" test program in C#

Basically, there is a main form that is called upon startup from the Program.cs - this is called frmParentForm.

I have a second form called frmChildForm

I only want one instance of frmChildForm, hence the Singleton usage. In This example, what i am aiming for is to type something into frmParentForm and press the button. Whatever is in the parent's text box will be appended to whatever is in the child form already.

(by the way, I use separate tabs to hold each form's coding - both have the same namespace. This keeps the coding tidy).

This is the code of frmParentForm:-

using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace PassingDataExample<br />
{<br />
    public partial class frmParentForm : Form<br />
    {<br />
        public frmParentForm()<br />
        {<br />
            InitializeComponent();<br />
        }<br />
<br />
        public void btnSendToNextForm_Click(object sender, EventArgs e)<br />
        {<br />
            frmChildForm.frm.Enabled = true;<br />
            frmChildForm.frm.Visible = true;<br />
            frmChildForm.frm.Show();<br />
            frmChildForm.frm.Focus();<br />
            frmChildForm.frm.textBox1.Text = "xyz";<br />
            //frmChildForm.frm.textBox1.AppendText(textBox1.Text);<br />
        }<br />
    }<br />
}


This is the code of frmChildForm:-

using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace PassingDataExample<br />
{<br />
    public partial class frmChildForm : Form<br />
    {<br />
<br />
        public static frmChildForm frm;<br />
<br />
        public static frmChildForm GetInstance()<br />
        {<br />
            if (frm == null)<br />
            {<br />
                frm = new frmChildForm();<br />
            }<br />
            return frm;<br />
        }<br />
<br />
        private frmChildForm()<br />
        {<br />
            InitializeComponent();<br />
        } <br />
        private void btnClose_Click(object sender, EventArgs e)<br />
        {<br />
            this.Close();<br />
        }<br />
<br />
    }<br />
}


When I run this code, frmParentForm is displayed ok, but when I press the btnSendToNextForm_Click, I get the error "Object reference not set to an instance of an object" on the first access line "frmChildForm.frm.Enabled = true;" - Why? I thought a Singleton Form was meant to be usable program-wide.

By the way, the list of frmChildForm code in the parent form may or may not be correct - it's just where I have been trying different things. The essence is that the first instance gives the error.

Anyone have any ideas please?
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
Luc Pattyn15-Feb-11 5:20
sitebuilderLuc Pattyn15-Feb-11 5:20 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 9:28
Edunt15-Feb-11 9:28 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Luc Pattyn15-Feb-11 10:10
sitebuilderLuc Pattyn15-Feb-11 10:10 
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
musefan15-Feb-11 5:26
musefan15-Feb-11 5:26 
GeneralRe: Singleton Form updated from main Form - Object Reference Error Pin
Edunt15-Feb-11 9:45
Edunt15-Feb-11 9:45 
AnswerRe: Singleton Form updated from main Form - Object Reference Error Pin
_Erik_15-Feb-11 5:47
_Erik_15-Feb-11 5:47 
AnswerRe: Singleton Form updated from main Form - Object Reference Error [modified] Pin
Edunt15-Feb-11 10:07
Edunt15-Feb-11 10:07 
Questionremove duplicates from list collection Pin
arkiboys15-Feb-11 0:40
arkiboys15-Feb-11 0:40 
AnswerRe: remove duplicates from list collection PinPopular
Pravin Patil, Mumbai15-Feb-11 0:53
Pravin Patil, Mumbai15-Feb-11 0:53 
GeneralRe: remove duplicates from list collection Pin
arkiboys15-Feb-11 0:57
arkiboys15-Feb-11 0:57 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:28
musefan15-Feb-11 1:28 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 1:49
mvePIEBALDconsult15-Feb-11 1:49 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 1:58
musefan15-Feb-11 1:58 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 4:07
mvePIEBALDconsult15-Feb-11 4:07 
GeneralRe: remove duplicates from list collection Pin
musefan15-Feb-11 4:12
musefan15-Feb-11 4:12 
GeneralRe: remove duplicates from list collection Pin
PIEBALDconsult15-Feb-11 4:31
mvePIEBALDconsult15-Feb-11 4:31 
GeneralRe: remove duplicates from list collection Pin
Pravin Patil, Mumbai15-Feb-11 1:50
Pravin Patil, Mumbai15-Feb-11 1:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.