473,406 Members | 2,707 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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


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
2 2003
"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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ward Bekker | last post by:
Hi, I am researching if it is possible to incorporate the web forms designer that is used by visual studio in another application. Hosting the WIN forms designer is already possible (see...
1
by: MLongmire | last post by:
I'm trying to create a ComboBox class that will present the same printout options to users no matter where I need to use the combo box. I extend the ComboBox class and in the constructor I add...
2
by: Jim | last post by:
I have some complex (fairly) user controls that I have created. Some of those user controls host other user controls. When I host one of these on a WinForm, I sometimes run into problems where...
1
by: Jim | last post by:
I have some complex (fairly) user controls that I have created. Some of those user controls host other user controls. When I host one of these on a WinForm, I sometimes run into problems where...
6
by: TryingLikeHeck | last post by:
I have a UserControl that must have 2 fields initialized before some of the prorperties are used. So I added a new New sub with arguments. If I leave the old New in there the control could be...
13
by: cj | last post by:
In a project done in 2003 about a year ago I was told to add the SocketWrench code below into the Windows Form Designer generated code area as shown below. #Region " Windows Form Designer...
2
by: PGP | last post by:
I recently derived from a ComboBox to make a countries combo and included it in couple of forms. The derived combo box loads an xml list of countries and uses the DataSource and DisplayMember...
6
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
Yesterday Visual Studio gave me a strange error both at compiletime and at designtime that had no obvious connection to anything I had changed recently. After some effort tracking down the problem...
2
by: someshbakliwal | last post by:
Hi, I have created some autopopulating combo boxes on my HTML page (script- Javascript). so these combo boxes are autopopulated with choices made in previous combo boxes. The problem I am facing is...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.