By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,728 Members | 2,462 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,728 IT Pros & Developers. It's quick & easy.

How can I stop VS designer from initializing my combo box?

P: n/a

I have the very simple derived class below but when I drag the class from the toolbox on to one of my UserControls VS designer
extracts the information and puts it into its resource database for the control. Then when I build and run the control I find that
the LineWidthComboBox quite often appears with 2 copies of the item list. I.e. 8 entries instead of 4.

This usually only happens after I have run the application and can happen even after I have gone through and deleted every
collection in my app that appears in the Properties panel.

I can't find the consistency in this yet but I can see where it generates the item list in InitializeComponent. Is there a way of
stopping designer doing this? I cannot move the initialization to OnCreateControl() because I initialize the SelectedIndex for the
combobox before that and the regeneration of it's contents means that the selection gets lost.

How do I stop designer generating the item list? I have over 100 instances of this combo box and a similarly designed one in my
application and it takes ages to fix up what designer does. The whole purpose in creating the class was to centralize the ComboBox
items so that I would only need to change it in one place but designer in one fell swoop has destroyed all this and made my life a
living hell.

if I was to generate the list from a database my code would never work because designer would have trashed my initialization.

Any ideas on how to get rid of this problem would be very, very much appreciated.
Thanks

Steve


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Graphics2D
{
public class LineWidthComboBox : System.Windows.Forms.ComboBox
{

public LineWidthComboBox()
{
this.DropDownStyle = ComboBoxStyle.DropDownList;

this.Size = new Size(85, 24);
this.Font = new Font("Microsoft San Serif",
9.00f,
FontStyle.Regular);
this.BeginUpdate();
this.Items.Clear();
this.Items.Add("Narrow");
this.Items.Add("Normal");
this.Items.Add("Wide");
this.Items.Add("Extra Wide");
this.EndUpdate();
}

}
}
Oct 15 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"steve" <s_******@yahoo.comwrote in message
news:6t********************************@4ax.com...
How do I stop designer generating the item list?
How about overriding SetItemsCore() and adding your items there instead of
in the constructor?
Oct 15 '08 #2

P: n/a
"steve" <s_******@yahoo.comwrote in message
news:6t********************************@4ax.com...

I should have added: I'd recommend asking future questions that are specific
to WinForms in the microsoft.public.dotnet.framework.windowsforms.* groups,
or at least crossposting to one or more of those groups. Maybe a VB guy has
had the same problem but never reads this group, y'know?
Oct 15 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.