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();
}
}
}