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:
* Get free support
* Communicate privately with other members (PM).
* Removal of this message
* 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
Go Back   Tech Support Forum > The Conversation Pit > Programming
User Name
Password
Site Map Register Donate Rules Blogs Mark Forums Read

Programming A discussion forum for programs and programming used in tech-related businesses.

Reply
 
Thread Tools
Old 03-09-2008, 05:33 PM   #1 (permalink)
Registered User
 
Join Date: Mar 2008
Location: NE Illinois
Posts: 1
OS: WinXP


Confused Using Singleton Pattern in iComparer Interface Class

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.GetInstance() ;
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.
Attached Files
File Type: txt Form1.txt (8.3 KB, 0 views)
File Type: txt ListViewColumnSorter.txt (6.8 KB, 0 views)
AlbreK01 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Bookmark on Thread SoupReddit!
Reply With Quote
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -7. The time now is 06:40 PM.



Copyright 2001 - 2008, Tech Support Forum

Search Engine Friendly URLs by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81