Using inheritited combobox, fill in the constuctor

P

Peter

Hello

I will use inherited comboboxes to provide Application wide
Information in all Dialogs e.g.

-Status Information from enum's
-Simple Information from the database (e.g. unit of measurement, kg,
m, ….)

I inherit my own combobox and fill it in the constructor

public class MyComboBox:Combobox
{
public MyComboBox()
{
// fill from database or enum
// e.g.
for (int I=1; I<10; I++)
this.Items.Add(I);
}
}

Using myCombobox in the Form-Designer is easy.
Starting the application all Items in myCombobox are duplicated!
Because the form designer create code in the InitializeComponent()

this.comboBoxAktiv.Items.AddRange(new object[] {
1,
2,
3,
…,
9});

obviously the Form Designer create a instance of myCombobox and use
the Content to build an array of Objects using add range…

I cant believe that. Using inheritance makes no sense.
Particularly filling from database is impossible.

Is there a possibility to prevent the code generation ?

Peter
 
C

Claes Bergefall

Override the Items property and set the following attributes:
DesignerSerializationVisibility: Hidden
Browsable: False
EditorBrowsable: Never

That way the property will not be visible in the designer or in
the intelisense list and no code will be generated for it

/claes
 
P

Peter

Thanks for the reply Claes.
it works

Peter

Claes Bergefall said:
Override the Items property and set the following attributes:
DesignerSerializationVisibility: Hidden
Browsable: False
EditorBrowsable: Never

That way the property will not be visible in the designer or in
the intelisense list and no code will be generated for it

/claes


Peter said:
Hello

I will use inherited comboboxes to provide Application wide
Information in all Dialogs e.g.

-Status Information from enum's
-Simple Information from the database (e.g. unit of measurement, kg,
m, ..)

I inherit my own combobox and fill it in the constructor

public class MyComboBox:Combobox
{
public MyComboBox()
{
// fill from database or enum
// e.g.
for (int I=1; I<10; I++)
this.Items.Add(I);
}
}

Using myCombobox in the Form-Designer is easy.
Starting the application all Items in myCombobox are duplicated!
Because the form designer create code in the InitializeComponent()

this.comboBoxAktiv.Items.AddRange(new object[] {
1,
2,
3,
.,
9});

obviously the Form Designer create a instance of myCombobox and use
the Content to build an array of Objects using add range.

I cant believe that. Using inheritance makes no sense.
Particularly filling from database is impossible.

Is there a possibility to prevent the code generation ?

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top