none
ToolStripComboBox displays in incorrect location RRS feed

  • Question

  • Hi All,

    When the we add ToolStripComboBox in a ToolStripMenuItem in the ContextMenustrip's opening event, displays the ToolStripComboBox in the TopLeft corner of the screen when displaying for the second time.

    create a sample using the below code.
    Right click the item in list box.
    Click the menu item.
    Notice the combobox
    Again right click the item in list box.
    Click the menu item
    Notice the combobox location.


    The issue is reproduced only when adding the ToolStripmenuitem at runtime in Contrextmenustrip's opening event.

    code I used:

    ToolStripComboBox _MenuComboBoxItem;
            ToolStripComboBox _MenuComboBoxItem2;
            public Form1()
            {
                InitializeComponent();
                this.listBox1.ContextMenuStrip = contextMenuStrip1;
                this.listBox1.Items.Add("test");

                _MenuComboBoxItem = new ToolStripComboBox();
                _MenuComboBoxItem.Text = "test";
                _MenuComboBoxItem.ToolTipText = "test";
                _MenuComboBoxItem.Items.AddRange(new string[] { "Test1", "Test2", "Test3", "Test4" });
              
                _MenuComboBoxItem2 = new ToolStripComboBox();
                _MenuComboBoxItem2.Text = "test";
                _MenuComboBoxItem2.ToolTipText = "test";
                _MenuComboBoxItem2.Items.AddRange(new string[] { "Test1", "Test2", "Test3", "Test4" });
            }
         
            private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
            {
              contextMenuStrip1.Items.Clear();

                ToolStripMenuItem mainItem = new ToolStripMenuItem("TEST: ");
               
                contextMenuStrip1.Items.Add(mainItem);
                mainItem.DropDownItems.Add(_MenuComboBoxItem);
               //Adding two ToolStripComboBoxEx does not cause the issue
                //mainItem.DropDownItems.Add(_MenuComboBoxItem2);
                   e.Cancel = false;
            }


    Regards,
    Shiny

    • Edited by Shine Nalini Tuesday, March 24, 2009 11:21 AM Testing
    Tuesday, March 24, 2009 10:48 AM

All replies