473,505 Members | 13,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Designer Flaw?

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 the values I use during instantiation.
This behavior is annoying. When I run the program two sets of options
appear in the drop down. On top of the AddRange() call being injected, the
values for the AddRange() call are converted from variable references to
literal values. If I use the combo box throughout my
application and then decide to change the values of the variables, I'll have
to search and replace the literal values, instead of changing the
values in the class.
Here is a sample. I used sharpDevelop, but the problem(?) occurs in
devStudio, also.
using System;
using System.Drawing;
using System.Windows.Forms;
namespace WinFormsTest {
public class MainForm : System.Windows.Forms.Form {
public MainForm() {
InitializeComponent();
}
[STAThread]
public static void Main(string[] args) {
Application.Run(new MainForm());
}
private void InitializeComponent() {
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 271);
this.Name = "MainForm";
}
}
public class PrintComboBox : System.Windows.Forms.ComboBox {
public PrintComboBox() {
Items.Add( DEST_SCREEN );
Items.Add( DEST_FILE );
Items.Add( DEST_EMAIL );
DropDownStyle = ComboBoxStyle.DropDownList;
SelectedIndex = 0;
}
private const String DEST_SCREEN = "View";
private const String DEST_FILE = "File";
private const String DEST_EMAIL = "eMail";
}

}
When you switch to design mode, the PrintComboBox will appear in the Custom
Components section of the toolbox. Add the combo box to the form, then
check the source code and you'll see this statement will have been added to
MainForm.InitializeComponent().

this.printComboBox1.Items.AddRange(new object[] {
"View",
"File",
"eMail"});
There must be some explanation, since both devStudio and sharpDevelop
produce the same results.
Is this typical behaviour?

Am I implementing this correctly?
Thanks,
Mark


Nov 17 '05 #1
1 1164
I'm not 100% sure that this will work, but in your PrintComboBox class,
have you tried adding this:

private bool ShouldSerializeItems()
{
if (base.Items.Count != 3)
{
return true;
}
if (!base.Items[0].GetType().Equals(typeof(string)) ||
(string)base.Items[0] != DEST_SCREEN)
{
return true;
}
if (!base.Items[1].GetType().Equals(typeof(string)) ||
(string)base.Items[1] != DEST_FILE)
{
return true;
}
if (!base.Items[2].GetType().Equals(typeof(string)) ||
(string)base.Items[2] != DEST_EMAIL)
{
return true;
}
return false;
}

You have to tell the Designer that your combo box contains the default
items and that so long as it has those items the Designer shouldn't
serialize the Items list. Now, I have some doubts about whether this
will work, because you can't override Items in your derived class, so
the Items property is in the base ComboBox class while the derived
ShouldSerializeItems property is in your derived class. Nonetheless,
it's worth a shot.

You might also want to post this question in the newsgroup
microsoft.public.dotnet.windowsforms.designtime group, as this is a
design time problem with your class. Someone there will surely know how
to fix you up.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2761
by: Christian Engström | last post by:
If you have a function that returns something by value, the gcc compiler (version 3.2.3 on Windows XP with MinGW) converts the returned value from the type you specify in the code, to the const...
10
2217
by: ma740988 | last post by:
I'm hoping my post here doesn't fall into the 'hard to say' category, nonetheless I've been advised that multiple uses of accessor/mutator (get/set) member functions can be viewed as a 'design...
5
2323
by: christophe (dot) poucet (at) gmail (dot) com | last post by:
Hello, I noticed there is a flaw in the vector implementation of g++ (3.4). Basically when you erase an element from a vector, it calls the wrong destructor. In most cases this is not such a...
23
1714
by: Java script Dude | last post by:
Give this a test in IE (verified in IE 6.0 sp2) Has anybody else seen this and is there a workaround besides escaping with html special chars and not using IE ;] ~ file 1 ~ <html> <head>...
8
1911
by: Matt Kruse | last post by:
http://news.zdnet.com/2100-1009_22-6121608.html Hackers claim zero-day flaw in Firefox 09 / 30 / 06 | By Joris Evers SAN DIEGO--The open-source Firefox Web browser is critically flawed in...
2
4676
by: dejavue82 | last post by:
Does anybody know how to resolve the following errors? They were caused by the designer.cs file that was auto-generated by the LINQ to SQL designer. I am using the March 2007 Orcas CTP version of...
3
1825
by: Windows | last post by:
Microsoft Windows | MSN Flaw I have found a flaw in MSN. For those that use MSN or Live.com with Windows see:...
4
2625
by: Goran Djuranovic | last post by:
Hi all, I am experiencing a strange thing happening with a "designer.vb" page. Controls I manually declare in this page are automatically deleted after I drop another control on a ".aspx" page. -...
1
2052
by: Guy Macon | last post by:
Serious Security Flaw in Google Chrome: http://www.readwriteweb.com/archives/security_flaw_in_google_chrome.php -- Guy Macon <http://www.GuyMacon.com/>
0
7213
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
7098
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
7298
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,...
1
7017
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...
0
4698
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...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.