Visual inheritance bug?

T

Tim A.

Hello gurus!

In my C# project I have a localized form that I use as the prototype for two
others. The prototype form has a ListBox control data bound to an ArrayList
containing data elements of a custom class type. At design time its Items
collection is empty and is populated by data binding only when the
application is executed and the underlying ArrayList collection is created.

The inherited forms' ListBox controls seem to somehow mysteriously inherit
not only the properties of the prototype form's ListBox control, but also
its Items collection. It sounds crazy, but I get errors at compile time
which are caused by the code Windows Forms Designer automatically inserts
into the InitializeComponent() method. This is what it looks like:

this.lstItems.Items.AddRange(new object[] {
((object)(resources.GetObject("lstItems.Items"))),
((object)(resources.GetObject("lstItems.Items1"))),
((object)(resources.GetObject("lstItems.Items2"))),
((object)(resources.GetObject("lstItems.Items3")))});

This line is inserted automatically every time I save the inherited form.
It seems that VS caches the number of elements in the Items collection the
last time the application is run in debug mode and assumes the elements
exist in the resource file, which they don't.

Any ideas how to get rid of this annoying behaviour?

P.S. If you reply directly, please remove the anti-spamming proclamation
from my e-mail address.
 
S

Sanjeeva

Its not because of the arraylist items , the localized form stores all the
information regarding controls in the resource files.
There fore the second file is also copying the Resx file of the first
form... that's all.
 
T

Tim A.

Actually, no. The prototype form DOESN'T store the contents of the
listbox's Items collection in the resource file because at design time the
collection is empty. I even checked the resource file to make sure it has
no items in it. Neither are there any entries in the inherited form's
resource file, but the InitializeComponent() code still tries to read them.
That's what freaks me out!



Sanjeeva said:
Its not because of the arraylist items , the localized form stores all the
information regarding controls in the resource files.
There fore the second file is also copying the Resx file of the first
form... that's all.


--
Regards,
Sanjeeva
Proteans Software Solutions

Tim A. said:
Hello gurus!

In my C# project I have a localized form that I use as the prototype for two
others. The prototype form has a ListBox control data bound to an ArrayList
containing data elements of a custom class type. At design time its Items
collection is empty and is populated by data binding only when the
application is executed and the underlying ArrayList collection is created.

The inherited forms' ListBox controls seem to somehow mysteriously inherit
not only the properties of the prototype form's ListBox control, but also
its Items collection. It sounds crazy, but I get errors at compile time
which are caused by the code Windows Forms Designer automatically inserts
into the InitializeComponent() method. This is what it looks like:

this.lstItems.Items.AddRange(new object[] {
((object)(resources.GetObject("lstItems.Items"))),
((object)(resources.GetObject("lstItems.Items1"))),
((object)(resources.GetObject("lstItems.Items2"))),
((object)(resources.GetObject("lstItems.Items3")))});

This line is inserted automatically every time I save the inherited form.
It seems that VS caches the number of elements in the Items collection the
last time the application is run in debug mode and assumes the elements
exist in the resource file, which they don't.

Any ideas how to get rid of this annoying behaviour?

P.S. If you reply directly, please remove the anti-spamming proclamation
from my e-mail address.
 
T

Tim A.

The culprit was the ListBox component's Items property that by default
persists its contents. I had to create my own version of the list box
control that derives from ListBox and overrides its Items property so that
it doesn't persist its contents. Here's what it looks like:

public class CPUListBox : System.Windows.Forms.ListBox
{
// Other code....

[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new ObjectCollection Items
{
get { return base.Items; }
}

}



Tim A. said:
Actually, no. The prototype form DOESN'T store the contents of the
listbox's Items collection in the resource file because at design time the
collection is empty. I even checked the resource file to make sure it has
no items in it. Neither are there any entries in the inherited form's
resource file, but the InitializeComponent() code still tries to read them.
That's what freaks me out!



Sanjeeva said:
Its not because of the arraylist items , the localized form stores all the
information regarding controls in the resource files.
There fore the second file is also copying the Resx file of the first
form... that's all.


--
Regards,
Sanjeeva
Proteans Software Solutions

Tim A. said:
Hello gurus!

In my C# project I have a localized form that I use as the prototype
for
two
others. The prototype form has a ListBox control data bound to an ArrayList
containing data elements of a custom class type. At design time its Items
collection is empty and is populated by data binding only when the
application is executed and the underlying ArrayList collection is created.

The inherited forms' ListBox controls seem to somehow mysteriously inherit
not only the properties of the prototype form's ListBox control, but also
its Items collection. It sounds crazy, but I get errors at compile time
which are caused by the code Windows Forms Designer automatically inserts
into the InitializeComponent() method. This is what it looks like:

this.lstItems.Items.AddRange(new object[] {
((object)(resources.GetObject("lstItems.Items"))),
((object)(resources.GetObject("lstItems.Items1"))),
((object)(resources.GetObject("lstItems.Items2"))),
((object)(resources.GetObject("lstItems.Items3")))});

This line is inserted automatically every time I save the inherited form.
It seems that VS caches the number of elements in the Items collection the
last time the application is run in debug mode and assumes the elements
exist in the resource file, which they don't.

Any ideas how to get rid of this annoying behaviour?

P.S. If you reply directly, please remove the anti-spamming proclamation
from my e-mail address.
 

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