Windows Develop Bookmark and Share   
 index > Windows Forms General > ListBox is empty when hosted in ToolStripControlHost and ToolStripDropDown
 

ListBox is empty when hosted in ToolStripControlHost and ToolStripDropDown

hi every one.

i have a listBox.

and i am defining a ToolStripControlHost that host the listbox

and i am adding the host control to a ToolStripDropDown

now when changing the DataSource of the ListBox nothing happen and the listBOx is empty??

 public class Person
        {
            public string Name { get; set; }
            public Person(string name)
            {
                Name = name;
            }
        }

private void Form1_Load(object sender, EventArgs e)
        {
            ListBox lstBox = new ListBox();
            lstBox.DataSource = new List<Person> { new Person("Nour"), new Person("Ahmad") };
            lstBox.DisplayMember = "Name";

            //Controls.Add(lstBox);
         
            ToolStripControlHost host = new ToolStripControlHost(lstBox);
            host.AutoSize = false;

            ToolStripDropDown dropDown = new ToolStripDropDown();
            dropDown.AutoClose = false;
            dropDown.AutoSize = false;
            dropDown.Items.Add(host);

            dropDown.Show(this, 0, 0);
        }
now if you uncomment the
Controls.Add(lstBox);


the listbox works fine???
what does that mean?
i code so , I'm exists.
NoOoOoR  Sunday, September 06, 2009 10:32 AM

You need to have a windows forms control, the toolstripControlHost will host the windows forms control.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byNoOoOoR Wednesday, September 16, 2009 8:22 AM
  •  
Ling Wang  Sunday, September 13, 2009 10:32 AM

You need to have a windows forms control, the toolstripControlHost will host the windows forms control.

Best regards,

Ling Wang


Please remember to click “Mark as Answer�on the post that helps you, and to click “Unmark as Answer�if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Marked As Answer byNoOoOoR Wednesday, September 16, 2009 8:22 AM
  •  
Ling Wang  Sunday, September 13, 2009 10:32 AM
it worked, but the question is : what does the DataSource property has to do with the parent of ListBox?? i mean why should i host the listbox in a user control to make it show the items?? although the DataGridView didn't expose such behavior!
i code so , I'm exists.
NoOoOoR  Wednesday, September 16, 2009 8:27 AM

You can use google to search for other answers

Custom Search

More Threads

• Big buttons toolstrip
• .gif Form use
• Application has generated an exception that could not be handled.
• Picture Box Image in the parent form
• how to scroll a disabled listview
• Changing border color of GroupBox
• Help with save dialogs and open dialogs ect. HElp! and signtool.exe error! (sorry if this is wrong board)
• Timer problem?
• shutting down the computer
• How to call a B function/method of a MDI parent (Form1)?