Jump to content

Howto: Populate info into combobox

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
dirkfirst

dirkfirst

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 354 posts
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


        private void Form1_Load(object sender, EventArgs e)

        {

            comboBox1.Items.Add("Object 1");

            comboBox1.Items.Add("Object 2");

        }


You can use the same thing to remove items


        private void Form1_Load(object sender, EventArgs e)

        {

            comboBox1.Items.Add("Object 1");

            comboBox1.Items.Add("Object 2");


            comboBox1.Items.Remove("Object 1");

        }



#2
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts
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.

#3
Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guests

brackett said:

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.


What is Message Pump? I've never heard of BeginUpdate or EndUpdate - does this keep it from showing each insert as it is inserted?

#4
brackett

brackett

    Programmer

  • Members
  • PipPipPipPip
  • 192 posts

NeedHelp said:

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.

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.