Click here to Skip to main content
15,913,910 members
Home / Discussions / C#
   

C#

 
GeneralRe: Adding Checkbox to List view Pin
satyam1432-May-07 3:47
satyam1432-May-07 3:47 
GeneralRe: Adding Checkbox to List view Pin
AFSEKI7-May-07 6:26
AFSEKI7-May-07 6:26 
QuestionInstallation program for multiple applications? Pin
Fredand132-May-07 3:38
Fredand132-May-07 3:38 
AnswerRe: Installation program for multiple applications? Pin
LongRange.Shooter2-May-07 4:59
LongRange.Shooter2-May-07 4:59 
QuestionGenerics Pin
Malcolm Smart2-May-07 3:21
Malcolm Smart2-May-07 3:21 
AnswerRe: Generics Pin
PIEBALDconsult2-May-07 3:43
mvePIEBALDconsult2-May-07 3:43 
GeneralRe: Generics Pin
Malcolm Smart2-May-07 3:53
Malcolm Smart2-May-07 3:53 
GeneralRe: Generics Pin
Ian Shlasko2-May-07 4:43
Ian Shlasko2-May-07 4:43 
You can't change the ancestors of existing classes (Without rewriting them), but with a little extra work, you could encapsulate them into a host control.

public class GenericListBox<T> : Control
  where T : ListControl
{
   public GenericListBox(data...)
   {
      T innerControl;

      if (typeof(T) == typeof(MyListBox))
        innerControl = new MyListBox(data);
      else if (typeof(T) == typeof(MyCheckedListBox))
        innerControl = new MyCheckedListBox(data);
      else
        throw new ArgumentException("Some descriptive error message");

      innerControl.Dock = DockStyles.Fill;
      this.Controls.Add(innerControl);
   }
}

...

GenericListBox<MyListBox> ctl = new GenericListBox<MyListBox>(someData);


Of course, you'd have to provide wrapper methods for many functions, or just expose the innerControl object as a ListControl and wrap any methods from below that on the inheritance chain.

Honestly though, I don't think this is the best way to do it. I'd suggest making a factory for it, and just passing an enum with the type of control to create:

public static ListControl CreateListControl(MyControlTypes ctlType, DataObject data)
{
  if (ctlType == MyControlTypes.NormalListBox)
    return new MyListBox(data);
  else
    return new MyCheckedListBox(data);
}

(MyControlTypes would be an enum, of course)

Of course, I might be misunderstanding you completely, but maybe this will spark an idea.
GeneralRe: Generics Pin
Malcolm Smart2-May-07 4:52
Malcolm Smart2-May-07 4:52 
QuestionExport SQL server database to access database file using c#.net Pin
Malayil alex2-May-07 2:49
Malayil alex2-May-07 2:49 
AnswerRe: Export SQL server database to access database file using c#.net Pin
J$2-May-07 10:22
J$2-May-07 10:22 
QuestionTime conversion Pin
Anka_Ame2-May-07 2:42
Anka_Ame2-May-07 2:42 
AnswerRe: Time conversion Pin
Luc Pattyn2-May-07 3:04
sitebuilderLuc Pattyn2-May-07 3:04 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 3:11
Anka_Ame2-May-07 3:11 
GeneralRe: Time conversion Pin
Luc Pattyn2-May-07 4:06
sitebuilderLuc Pattyn2-May-07 4:06 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 4:38
Malcolm Smart2-May-07 4:38 
AnswerRe: Time conversion Pin
Malcolm Smart2-May-07 3:31
Malcolm Smart2-May-07 3:31 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 3:36
Anka_Ame2-May-07 3:36 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 3:46
Malcolm Smart2-May-07 3:46 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 4:21
Anka_Ame2-May-07 4:21 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 4:35
Malcolm Smart2-May-07 4:35 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 5:01
Anka_Ame2-May-07 5:01 
GeneralRe: Time conversion Pin
Malcolm Smart2-May-07 5:02
Malcolm Smart2-May-07 5:02 
GeneralRe: Time conversion Pin
Anka_Ame2-May-07 5:10
Anka_Ame2-May-07 5:10 
GeneralRe: Time conversion Pin
Luc Pattyn2-May-07 5:24
sitebuilderLuc Pattyn2-May-07 5:24 

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.