473,789 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 LineWidthComboB ox 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 InitializeCompo nent. 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.Collecti ons.Generic;
using System.Componen tModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;

namespace Graphics2D
{
public class LineWidthComboB ox : System.Windows. Forms.ComboBox
{

public LineWidthComboB ox()
{
this.DropDownSt yle = ComboBoxStyle.D ropDownList;

this.Size = new Size(85, 24);
this.Font = new Font("Microsoft San Serif",
9.00f,
FontStyle.Regul ar);
this.BeginUpdat e();
this.Items.Clea r();
this.Items.Add( "Narrow");
this.Items.Add( "Normal");
this.Items.Add( "Wide");
this.Items.Add( "Extra Wide");
this.EndUpdate( );
}

}
}
Oct 15 '08 #1
2 2023
"steve" <s_******@yahoo .comwrote in message
news:6t******** *************** *********@4ax.c om...
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.c om...

I should have added: I'd recommend asking future questions that are specific
to WinForms in the microsoft.publi c.dotnet.framew ork.windowsform s.* 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
1370
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 http://divil.co.uk/net/articles/designers/hosting.asp for an example) But the 1.0 / 1.1 framework didn't had the needed functionality to be able to host the WEB forms designer.
1
1181
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 predefined print destinations, along with setting other properties. The problem comes when I drop the class onto the form in the designer. The code thats gets generated automatically "scrapes" the constructor and creates an AddRange() call for...
2
1997
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 the designer blows up with an "Object Reference Not Set to an Instance of an Object". Sometimes it even (so kindly) "munches" my code in the hosting control. Unfortunately, it seldm if ever tlss "where" exactly the problem occurred, and to my...
1
1893
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 the designer blows up with an "Object Reference Not Set to an Instance of an Object". Sometimes it even (so kindly) "munches" my code in the hosting control. Unfortunately, it seldm if ever tlss "where" exactly the problem occurred, and to my...
6
1011
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 used without initializing these fields so I removed it. Now if I try to use it the designer gets upset because there is no New() Is it posible to use only a New with arguments and still use the control in the Designer??
13
5259
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 generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer.
2
1905
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 properties to point to the appropriate node in xml. All this is done in the derived combo's constructor. This causes forms designer to load slower as it seems to initialize these derived combos with the country list. If i did not care about the...
6
3344
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 I discovered first a workaround, then the real cause of the problem. I would like to understand why what I am doing is frowned upon by Visual Studio and how to do this properly. My application is in one solution; supporting libraries including...
2
2306
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 that the combo boxes resize according to the length of the autopulating string. For example if the combo box autopopulates with option 'United States of America', the combo box will become wider and if it autopopulates with value 'NY' the combo box...
0
9666
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10408
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10199
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3700
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.