473,549 Members | 2,366 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

add values to a comboBox in VB.NET in Windows application.

Hello,

For my new Windows application, all I want is to create an initial
form to demo to the user to show them how it looks like with some data
on it. So I figure the fastest way is to create some comboBox-es to
show some data on them manually entered in the code without connecting
to the database yet. It should be simple but somehow I can't make it
work.

First, I drag a comboBox from the ToolBox to the form. Then,
double-click the form to go to the code behind page with the Load
event, I tried either:

ComboBox1.Items .AddRange(New Object() {"red", "blue"})
OR
ComboBox1.Items .Add("red")
ComboBox1.Items .Add("blue")

Yet when I ran, it showed nothing on the comboBox, except the word
"comboBox1" (default text property). Any ideas what I am missing,
anybody?

Or if you can tell me how create a comboBox display values from a
database the quickest way.

Thanks,
James
Nov 21 '05 #1
5 25831
Your code loads the combo box just fine. To eliminate the "ComboBox1" text,
either set the SelectedIndex of your combo box to a valid index (e.g. 0 or 1
with your example), which will select one of the values by default, or set
the Text property to an empty string, e.g.

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

or
Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Te xt = ""

You can find an example of binding a combobox to a database here:
http://msdn.microsoft.com/library/de...boxcontrol.asp

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
Hello,

For my new Windows application, all I want is to create an initial
form to demo to the user to show them how it looks like with some data
on it. So I figure the fastest way is to create some comboBox-es to
show some data on them manually entered in the code without connecting
to the database yet. It should be simple but somehow I can't make it
work.

First, I drag a comboBox from the ToolBox to the form. Then,
double-click the form to go to the code behind page with the Load
event, I tried either:

ComboBox1.Items .AddRange(New Object() {"red", "blue"})
OR
ComboBox1.Items .Add("red")
ComboBox1.Items .Add("blue")

Yet when I ran, it showed nothing on the comboBox, except the word
"comboBox1" (default text property). Any ideas what I am missing,
anybody?

Or if you can tell me how create a comboBox display values from a
database the quickest way.

Thanks,
James

Nov 21 '05 #2
"Russell Jones" <ar**@nospam.no rthstate.net> schrieb:
Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0


.... and if the user should not be able to enter text, set 'DropDownStyle' to
'DropDownList' (this will give a blank entry if 'SelectedIndex' is not set
to 0).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"Russell Jones" <ar**@nospam.no rthstate.net> wrote in message news:<eT******* *******@TK2MSFT NGP14.phx.gbl>. ..
Your code loads the combo box just fine. To eliminate the "ComboBox1" text,
either set the SelectedIndex of your combo box to a valid index (e.g. 0 or 1
with your example), which will select one of the values by default, or set
the Text property to an empty string, e.g.

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

or
Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Te xt = ""

You can find an example of binding a combobox to a database here:
http://msdn.microsoft.com/library/de...boxcontrol.asp

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
Hello,

For my new Windows application, all I want is to create an initial
form to demo to the user to show them how it looks like with some data
on it. So I figure the fastest way is to create some comboBox-es to
show some data on them manually entered in the code without connecting
to the database yet. It should be simple but somehow I can't make it
work.

First, I drag a comboBox from the ToolBox to the form. Then,
double-click the form to go to the code behind page with the Load
event, I tried either:

ComboBox1.Items .AddRange(New Object() {"red", "blue"})
OR
ComboBox1.Items .Add("red")
ComboBox1.Items .Add("blue")

Yet when I ran, it showed nothing on the comboBox, except the word
"comboBox1" (default text property). Any ideas what I am missing,
anybody?

Or if you can tell me how create a comboBox display values from a
database the quickest way.

Thanks,
James


Thank you both of you for responding and the link. When I tried:

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

It showed only "blue" on the comboBox. If I changed SelectedIndex to
1, it only showed "red".

I know I did not post my question clear earlier. Sorry about that.
This is what I need: when the comboxBox first shown, I'd like it to
show as "Select the color". However, when the user clicks the
comboBox, it should show the choice of "blue" and "red". How do I do
that?

James
Nov 21 '05 #4
Like dis....
ComboBox1.Items .Add("audi")
ComboBox1.Items .Add("buick")

ComboBox1.Items .Add("chevy")

ComboBox1.Items .Add("ford")

ComboBox1.Selec tedIndex = -1

ComboBox1.Text = "Pick a car"

Good Luck

Chris

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
"Russell Jones" <ar**@nospam.no rthstate.net> wrote in message
news:<eT******* *******@TK2MSFT NGP14.phx.gbl>. ..
Your code loads the combo box just fine. To eliminate the "ComboBox1"
text,
either set the SelectedIndex of your combo box to a valid index (e.g. 0
or 1
with your example), which will select one of the values by default, or
set
the Text property to an empty string, e.g.

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

or
Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Te xt = ""

You can find an example of binding a combobox to a database here:
http://msdn.microsoft.com/library/de...boxcontrol.asp

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
> Hello,
>
> For my new Windows application, all I want is to create an initial
> form to demo to the user to show them how it looks like with some data
> on it. So I figure the fastest way is to create some comboBox-es to
> show some data on them manually entered in the code without connecting
> to the database yet. It should be simple but somehow I can't make it
> work.
>
> First, I drag a comboBox from the ToolBox to the form. Then,
> double-click the form to go to the code behind page with the Load
> event, I tried either:
>
> ComboBox1.Items .AddRange(New Object() {"red", "blue"})
> OR
> ComboBox1.Items .Add("red")
> ComboBox1.Items .Add("blue")
>
> Yet when I ran, it showed nothing on the comboBox, except the word
> "comboBox1" (default text property). Any ideas what I am missing,
> anybody?
>
> Or if you can tell me how create a comboBox display values from a
> database the quickest way.
>
> Thanks,
> James


Thank you both of you for responding and the link. When I tried:

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

It showed only "blue" on the comboBox. If I changed SelectedIndex to
1, it only showed "red".

I know I did not post my question clear earlier. Sorry about that.
This is what I need: when the comboxBox first shown, I'd like it to
show as "Select the color". However, when the user clicks the
comboBox, it should show the choice of "blue" and "red". How do I do
that?

James

Nov 21 '05 #5
"Chris" <chris@No_Spam_ Please.com> wrote in message news:<ef******* *******@TK2MSFT NGP10.phx.gbl>. ..
Like dis....
ComboBox1.Items .Add("audi")
ComboBox1.Items .Add("buick")

ComboBox1.Items .Add("chevy")

ComboBox1.Items .Add("ford")

ComboBox1.Selec tedIndex = -1

ComboBox1.Text = "Pick a car"

Good Luck

Chris

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
"Russell Jones" <ar**@nospam.no rthstate.net> wrote in message
news:<eT******* *******@TK2MSFT NGP14.phx.gbl>. ..
Your code loads the combo box just fine. To eliminate the "ComboBox1"
text,
either set the SelectedIndex of your combo box to a valid index (e.g. 0
or 1
with your example), which will select one of the values by default, or
set
the Text property to an empty string, e.g.

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

or
Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Te xt = ""

You can find an example of binding a combobox to a database here:
http://msdn.microsoft.com/library/de...boxcontrol.asp

"James P." <ha*********@ya hoo.com> wrote in message
news:f4******** *************** ***@posting.goo gle.com...
> Hello,
>
> For my new Windows application, all I want is to create an initial
> form to demo to the user to show them how it looks like with some data
> on it. So I figure the fastest way is to create some comboBox-es to
> show some data on them manually entered in the code without connecting
> to the database yet. It should be simple but somehow I can't make it
> work.
>
> First, I drag a comboBox from the ToolBox to the form. Then,
> double-click the form to go to the code behind page with the Load
> event, I tried either:
>
> ComboBox1.Items .AddRange(New Object() {"red", "blue"})
> OR
> ComboBox1.Items .Add("red")
> ComboBox1.Items .Add("blue")
>
> Yet when I ran, it showed nothing on the comboBox, except the word
> "comboBox1" (default text property). Any ideas what I am missing,
> anybody?
>
> Or if you can tell me how create a comboBox display values from a
> database the quickest way.
>
> Thanks,
> James


Thank you both of you for responding and the link. When I tried:

Me.ComboBox1.It ems.AddRange(Ne w Object() {"red", "blue"})
Me.ComboBox1.Se lectedIndex = 0

It showed only "blue" on the comboBox. If I changed SelectedIndex to
1, it only showed "red".

I know I did not post my question clear earlier. Sorry about that.
This is what I need: when the comboxBox first shown, I'd like it to
show as "Select the color". However, when the user clicks the
comboBox, it should show the choice of "blue" and "red". How do I do
that?

James


Thank you so much, guys. It worked now.

James
Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1984
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is populated by sqlserver database table.When i select value from combobox ,value saved in to other table of my database and i use to datagrid to show...
2
2003
by: Balamurukan | last post by:
How to retrive property values from our own property window
0
2036
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows the available information based on the second combo box selection. But if I change my mind and select a different item in the second box, after the...
6
6399
by: dbuchanan | last post by:
Hello, Is this a bug? Is there some kind of work around? I want to add default values for a few columns in my datagridview I found the "DefaultValuesNeeded" event for the datagridview I gave it a try using the example given in
3
7500
by: Simon Tamman | last post by:
I've come across an interesting bug. I have workarounds but i'd like to know the root of the problem. I've stripped it down into a short file and hope someone might have an idea about what's going on. It's a simple program that loads a control onto a form and binds "Foo" against a combobox ("SelectedItem") for it's "Bar" property and a...
8
13383
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
This is the 2nd time posting so sorry for duplications. I am using VB.NT 2005 & a standard Combobox. I've been wracking my brain over this problem for a over a month & cannot seem to find a way to trap the pressing of a Tab Key when the focus is in a Combobox. The KeyDown or KeyUp event for a combobox will not fire when the tab key is...
3
5295
by: Gerrit | last post by:
Hi, I try to learn programming in c# with databinding controls. Now I have a problem with a ComboBox with the advanced properties for databinding, I want to set the DataSourceUpdateMode to OnPropertyChanged, but then the combobox does not display the right displaymember. Below is my sample code (it is working, when you paste it in a new...
1
4219
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound object when text is deleted. However bound object contains old value in this case. To reproduce: 1. Run code
2
3243
by: Andrus | last post by:
SWF DataGridView contains combobox control. Activating combobox and pressing F4 to open dropdown menu causes strange NRE (see below). When I enter some valid value to combobox, press tab, shift+tab , 44 dropdown menu opens OK. How to fix ? How to use VCSE 2008 with .net framework source code to find the line in
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7740
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7985
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.