Just learned how to do this. Here it is:
1) Add your combobox to your form
2) On button press or form load or whatever use
I used the Form1_Load
You can use the same thing to remove itemsCode:private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add("Object 1"); comboBox1.Items.Add("Object 2"); }
Code:private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add("Object 1"); comboBox1.Items.Add("Object 2"); comboBox1.Items.Remove("Object 1"); }
DirkFirst Tutorials | Linux Forum
IIRC, there's a BeginUpdate and EndUpdate method pair on the combobox as well. If you're going to insert a lot of items, it's worth it to call those for perf reasons - it'll basically disable message pump processing while adding items.
Originally Posted by brackett
What is Message Pump? I've never heard of BeginUpdate or EndUpdate - does this keep it from showing each insert as it is inserted?
The message pump is basically the thread that runs in your app and responds to user events (key presses and mouse clicks) and tells controls to repaint themselves.Originally Posted by NeedHelp
Yes - it keeps the control from responding to the repaint calls until EndUpdate is called - meaning it doesn't redraw itself as new items are being inserted. You could also use AddRange, which would allow you to add an array of objects at once.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks