Windows Develop Bookmark and Share   
 index > Windows Forms Designer > duplicate items in designer
 

duplicate items in designer

I have a TreeView derived control. By default the control is empty. I want to present user with some sample items so just after a call to InitializeComponent() I clear Nodes collection and add a few items (eg. item1, item1, item3) to it. The problem is that after some time of working with the designer I have item1, item2, item3, item1, item2, item3, item1, item2, item3, etc. on my list. It seems as if my items were magically moved to Designer.cs file over and over again. Is there any way to prevent this behaviour?
TomaszGrobelny  Thursday, June 25, 2009 9:44 PM
Try to add the items in the Load event handler of the form, and not in design mode
(this happens after few times that the designer add the items also in the designer.cs class and not just in the ctor.

private void Form2_Load(object sender, EventArgs e)

{

if (!DesignMode)

{

// add the items to the tree view

}

}


Eli Gazit (try this free icons site: http://www.iconbuffet.com/people/new?ref=EliGazit)
Eli Gazit  Friday, June 26, 2009 9:26 AM
First, I would like this sample data to be part of my control and not part of the form on which is is used (and I don't see Load event handler in TreeView). Second, I would like to display this sample data not only in design mode but also during runtime if no specific data is available.
TomaszGrobelny  Friday, June 26, 2009 6:58 PM
Sorry, I'm missed the part about the dervied from TreeView.

You can use (within the Ctor) the following code:

if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
// don't add items - design time
}
else
{
// add items - run time
}



Eli Gazit (try this free icons site: http://www.iconbuffet.com/people/new?ref=EliGazit)
Eli Gazit  Sunday, June 28, 2009 11:54 AM

You can use google to search for other answers

Custom Search

More Threads

• Creating a draggable control?
• strange toolbox behavior with IComponent
• play video on ax shockwave flash tool visual studio
• DefaultValueAttribute for .NET properties
• Relating Combos on Windows Forms
• extending the VS2005 MenuStrip designer
• Design time behavior - what do you prefer?
• Supporting 2003 & 2005 InitializeComponent
• Form resized by IDE
• User control crashes VS2005