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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve

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


    }

    }


    }
  • Jeff Johnson

    #2
    Re: How can I stop VS designer from initializing my combo box?

    "steve" <s_j_bull@yahoo .comwrote in message
    news:6tpbf4p06p i5n3j6gm5lp6nls 84bmipacd@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?


    Comment

    • Jeff Johnson

      #3
      Re: How can I stop VS designer from initializing my combo box?

      "steve" <s_j_bull@yahoo .comwrote in message
      news:6tpbf4p06p i5n3j6gm5lp6nls 84bmipacd@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?


      Comment

      Working...