![]() |
![]() |
![]() |
|||||
![]() |
![]() |
![]() |
![]() |
![]() |
|||
| Welcome
to Tech Support Forum home to more then 136,000 problems solved. Issues
have included: Spyware, Malware, Virus Issues, Windows, Microsoft,
Linux, Networking, Security, Hardware, and Gaming Getting your
problem solved is as easy as: 1. Registering for a free account 2. Asking your question 3. Receiving an answer Registered members: * See fewer ads. * And much more..
|
| Want to know how to post a question? click here | Having problems with spyware and pop-ups? First Steps |
|
|||||||
| Programming A discussion forum for programs and programming used in tech-related businesses. |
![]() |
|
|
Thread Tools |
|
|
#1 (permalink) |
|
Registered User
Join Date: Mar 2008
Location: NE Illinois
Posts: 1
OS: WinXP
|
I am writing a C# Windows app that will contain more than one ListView control. Because one form will contain more than one ListView control, I want to try to use the Singleton pattern on the implementation of my "iComparer" interface class.
The code compiles nicely, but at run time, I get the error of "Object Is Not Set To Instance Of An Object". Is there anything different I need to be doing to assign the singleton instance of my "iComparer" class to the ListViewItemSorter? Or, Is there some reason why I cannot make this a singleton and if so, how else can I define the "iComparer" class so that there is only one instance alive throughout the life of the application. I am attaching code files for reference, but here is some code snippets, too ....... From "Form1.CS" ListViewColumnSorter.GetInst ance() ;this.listBox1.ListViewItemSorter = (IComparer)(ListViewColumnSorter.GetInstance()) ; From "ListViewColumnSorter.cs" public sealed class ListViewColumnSorter : IComparer { /// <summary> /// ALBREK01 :: Define static singleton instance of class /// </summary> private static readonly ListViewColumnSorter instance = new ListViewColumnSorter() ; // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit // ALBREK01 :: Class constructor static ListViewColumnSorter() { InitColumnSorter () ; } // ALBREK01 :: Public access to singleton class instance public static ListViewColumnSorter GetInstance() { return (instance) ; } } Please help ....... I'm desperate. |
|
|
|
![]() |
| Thread Tools | |
|
|