Jump to content

Problem with comboBox control

- - - - -

  • Please log in to reply
7 replies to this topic

#1
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
ok...i puted comboBox on my form and i double click on that control...I entered next code:


comboBox1.Items.Add("Marc");


or


comboBox.Items.Insert(0,"Marc");


and there were not results in comboBox after I ran my program

what's the deal???

#2
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
Double clicking on the control in the designer generates a 'selected index changed' event handler. This is not what you want. Go back in the designer and select the form. Find the properties tab (should be on the right side, if not select 'view' from the menu bar and near the bottom you should find "Properties Window"). Now click on the lightning bolt icon (should be 4th icon across the top of the properties window) and you should see a list of events. You should see an event named 'Load'. Double click the box next to it and it will generate a Form_Load event handler. Put your code there.

#3
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
nothing dude...i'm confused...can you make a project for that and attach it here???

#4
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
Try this

Attached Files



#5
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
now i see...i put that code inside the combobox...whatis the difference in logic??? i thought that i should put it in combobox because i'm working with combobox...
tnx a lot

#6
zuludelta9

zuludelta9

    Newbie

  • Members
  • Pip
  • 1 posts

Tonchi said:

now i see...i put that code inside the combobox...whatis the difference in logic??? i thought that i should put it in combobox because i'm working with combobox...
tnx a lot

Whenever you double-click a control, it will take you to the default event of that control. For example if you have a ComboBox, most likely people are going to be selecting different things in the combo box (not typing into it to expecting an event). Hence when you double-clicked the ComboBox, it drew up the SelectedIndex_Changed event.

So whatever is in that event will happen when you select different items in that combo box. However, when you first run the form, your ComboBox is empty because there's nothing in it.

Single click your form on the designer and in the Properties window look for Events on the top and look for Form_Load. Once you double click that area, it should create the event for your Form (once it load, what happens?) This is where you type comboBox1.Items.Add("whatever");

#7
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
Well do this, Create a New Windows Form and double click it.
1.The Load event is implemented by visual studio for you
go back to design view add a combobox to the form.
2.Inside the load event write this code below
combobox1.Items.Add(new ListItem("CodeCall","LikeIt"));
let me know what happens now

#8
Tonchi

Tonchi

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 471 posts
  • Location:Varaždin
  • Programming Language:C, C++, C#
this is the result

Quote

Error 1 The type or namespace name 'ListItem' could not be found (are you missing a using directive or an assembly reference?)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users