locked
ComboBox Items Not Showing On Dropdown RRS feed

  • Question

  • Hi All,

     

    I am inheriting a windows form and modifying it in C#.  The parent form has three ComboBoxes and all are populated pragmatically to fit the user’s options.  In the parent form, the ComboBox Items are populating fine and there are no problems at runtime.  Yet, in the child form, none of the ComboBox items will show during runtime on Dropdown event.  Both are being set using the same algorithm, the only difference is the child form ComboBoxes are set in the child form constructor, and the parent form ComboBoxes are set in a sequence based on which items the user selects after the form loads.  Here is a sample of how the combo boxes are set in the child form:

     

    Code Block

    private void setComboBoxes()

    {

    cbMake.BeginUpdate();

    foreach (Make mk in makers.ToArray())

    cbMake.Items.Add(mk.Name);

    cbMake.EndUpdate();

     

    cbModel.BeginUpdate();

    foreach (Model mdl in make.Models)

    cbModel.Items.Add(mdl.Name);

    cbModel.EndUpdate();

     

    cbItems.BeginUpdate();

    foreach (IOrderItem itm in model.Equipment)

    cbItems.Items.Add(itm.Name);

    cbItems.EndUpdate();

    }

     

     

    I have stepped through the code on the child form and all of the items appear in the ComboBox.Items.InnerList collection as they should.  But at runtime, when the user clicks the down arrow to dropdown the items list, no items show. 

     

    Any advice offered would be much appreciated.

    Monday, December 24, 2007 2:59 PM

Answers

  • I've tried adding three ComboBoxes on a form, then create an inherited form from this form, put the following code in it

    Code Block


        public
    partial class ChildForm : Sample42.ParentForm

        {

            public ChildForm()

            {

                InitializeComponent();

                this.setComboBox();

            }

     

            private void setComboBox()

            {

                this.comboBox1.Items.Add("aaa");

                this.comboBox1.Items.Add("aaa");

                this.comboBox1.Items.Add("aaa");

     

                this.comboBox2.Items.Add("111");

                this.comboBox2.Items.Add("222");

                this.comboBox2.Items.Add("333");

     

                this.comboBox3.Items.Add("a1");

                this.comboBox3.Items.Add("v1");

                this.comboBox3.Items.Add("r1");

            }

        }

     

     



    But when showing the child form, it's no problem popuping the items.
    Maybe I misunderstand something, so would you please provide us the steps to reproduce your problem?

    Wednesday, December 26, 2007 3:35 AM
  • I wish I knew exactally how to reproduce the problem.  I've made another project with parent and child forms, implemented your code and the one I attempted and it works in the new project, but not on the one I'm currently working on.  

     

    But that's ok.  I took the easy route; I just copied and pasted the parent code to a new form, changed the class name and constructor in the new form, then added all the changes I wanted to implement in the child form to the new form.  Works spotlessly...

     

    Maybe VS is just trying to give me a hard time, but that's fine I found away around it. 

     

    Thanks for your help

    Wednesday, December 26, 2007 5:36 PM

All replies

  • I was wondering if you were calling setComboBoxes from a thread since you are seeing the items in the combobox's items innerlist but they are not showing up in the ui.
    Monday, December 24, 2007 5:40 PM
  • Thanks for replying Ken,

     

    The setComboBoxes method I'm using is being used by the same thread as the Main method in the static Program class.  It is called by the constructor of an inherited form and both parent and child forms are called by the same class (MainForm.cs). 

     

    If this helps at all; Visual Studio 2005 will not allow me to edit the form in UI viewer (MyForm.cs [Design]).  It keeps giving me the error message: "Constructor on type 'MyNamespace.MyForm.MyClass' not found".  Yet, I am explicitly assigning the child form constructor, and passing the required arguments to the base class Form.  This error also makes no sense because at runtime the form is instantiating just fine.  The child form loads with all the components of the base form and reflects the passed arguments (to make sure, I passed a string argument to change the Form.Text property from child to base form, it works).  The only thing is all the combo boxes show nothing on dropdown.

     

    I hope this additional info helps to trouble-shoot.  I wasn't sure if these two problems were related or not, so I tried to isolate the main problem as much as I could.

     

    Hope you have a hunch

    Monday, December 24, 2007 7:03 PM
  • I've tried adding three ComboBoxes on a form, then create an inherited form from this form, put the following code in it

    Code Block


        public
    partial class ChildForm : Sample42.ParentForm

        {

            public ChildForm()

            {

                InitializeComponent();

                this.setComboBox();

            }

     

            private void setComboBox()

            {

                this.comboBox1.Items.Add("aaa");

                this.comboBox1.Items.Add("aaa");

                this.comboBox1.Items.Add("aaa");

     

                this.comboBox2.Items.Add("111");

                this.comboBox2.Items.Add("222");

                this.comboBox2.Items.Add("333");

     

                this.comboBox3.Items.Add("a1");

                this.comboBox3.Items.Add("v1");

                this.comboBox3.Items.Add("r1");

            }

        }

     

     



    But when showing the child form, it's no problem popuping the items.
    Maybe I misunderstand something, so would you please provide us the steps to reproduce your problem?

    Wednesday, December 26, 2007 3:35 AM
  • I wish I knew exactally how to reproduce the problem.  I've made another project with parent and child forms, implemented your code and the one I attempted and it works in the new project, but not on the one I'm currently working on.  

     

    But that's ok.  I took the easy route; I just copied and pasted the parent code to a new form, changed the class name and constructor in the new form, then added all the changes I wanted to implement in the child form to the new form.  Works spotlessly...

     

    Maybe VS is just trying to give me a hard time, but that's fine I found away around it. 

     

    Thanks for your help

    Wednesday, December 26, 2007 5:36 PM
  • I'm maintaining WinCE software written with WinForms, and just run into this situation. Drop down won't show up for ComboBox, though selection can still bee changed by arrow keys on keyboard. The fix is simple after two hours research: just move the ComboBox "higher" on the form (like from Location 20, 200 to 20, 50), so that there is room for the drop down to show.
    Wednesday, April 27, 2016 2:21 AM
  • I have the same problem, however I found that the dropdown would not open when you clicked the dropdown arrow...

    But I click on the item description (select by hitting the actual wording in the dropdown it would show).

    Weird

    Saturday, August 22, 2020 12:30 AM