473,405 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 25822
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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 0

or
Me.ComboBox1.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.Text = ""

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

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
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.northstate.net> schrieb:
Me.ComboBox1.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 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.northstate.net> wrote in message news:<eT**************@TK2MSFTNGP14.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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 0

or
Me.ComboBox1.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.Text = ""

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

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 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.SelectedIndex = -1

ComboBox1.Text = "Pick a car"

Good Luck

Chris

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
"Russell Jones" <ar**@nospam.northstate.net> wrote in message
news:<eT**************@TK2MSFTNGP14.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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 0

or
Me.ComboBox1.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.Text = ""

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

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
> 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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 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**************@TK2MSFTNGP10.phx.gbl>...
Like dis....
ComboBox1.Items.Add("audi")
ComboBox1.Items.Add("buick")

ComboBox1.Items.Add("chevy")

ComboBox1.Items.Add("ford")

ComboBox1.SelectedIndex = -1

ComboBox1.Text = "Pick a car"

Good Luck

Chris

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
"Russell Jones" <ar**@nospam.northstate.net> wrote in message
news:<eT**************@TK2MSFTNGP14.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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 0

or
Me.ComboBox1.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.Text = ""

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

"James P." <ha*********@yahoo.com> wrote in message
news:f4**************************@posting.google.c om...
> 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.Items.AddRange(New Object() {"red", "blue"})
Me.ComboBox1.SelectedIndex = 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
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...
2
by: Balamurukan | last post by:
How to retrive property values from our own property window
0
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...
6
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...
3
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...
8
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...
3
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...
1
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...
2
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.