PC Review


Reply
Thread Tools Rate Thread

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

 
 
James P.
Guest
Posts: n/a
 
      18th Nov 2004
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
 
Reply With Quote
 
 
 
 
Russell Jones
Guest
Posts: n/a
 
      18th Nov 2004
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      18th Nov 2004
"Russell Jones" <(E-Mail Removed)> 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/>

 
Reply With Quote
 
James P.
Guest
Posts: n/a
 
      19th Nov 2004
"Russell Jones" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      19th Nov 2004
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." <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> "Russell Jones" <(E-Mail Removed)> wrote in message
> news:<(E-Mail Removed)>...
>> 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." <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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



 
Reply With Quote
 
James P.
Guest
Posts: n/a
 
      21st Nov 2004
"Chris" <chris@No_Spam_Please.com> wrote in message news:<(E-Mail Removed)>...
> 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." <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
> > "Russell Jones" <(E-Mail Removed)> wrote in message
> > news:<(E-Mail Removed)>...
> >> 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." <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Howto make Combobox requery based on dependant combobox values Shane Microsoft Access Form Coding 1 22nd Apr 2008 09:14 AM
Question on Windows Application ComboBox =?Utf-8?B?V0I=?= Microsoft Dot NET 2 12th Jun 2006 06:33 PM
updating data in windows application datagrid according to the value selected in combobox Yasmina Baydoun via .NET 247 Microsoft ADO .NET 1 19th May 2005 04:50 PM
Fill values into a listbox matching selected values from a combobox Jon Microsoft Excel Programming 4 25th Jan 2005 04:25 PM
Values contained in value list of second combobox based on value selected in first combobox. Anthony Microsoft Access Forms 16 6th Mar 2004 04:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:42 AM.