473,395 Members | 1,568 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,395 software developers and data experts.

Setting Combo box text property

I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.
How do I do it?
Thanks

Nov 21 '05 #1
8 6082
Set the Combo Box's Selected Index to 0 in the formload event.

Venkat

"VB User" wrote:
I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.
How do I do it?
Thanks

Nov 21 '05 #2
Is there some other property I should set. Setting Selected Index does not
help. It simply reads the text property I set during design time.
"vvenk" wrote:
Set the Combo Box's Selected Index to 0 in the formload event.

Venkat

"VB User" wrote:
I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.
How do I do it?
Thanks

Nov 21 '05 #3
Nope.

The code below selects the first item on the combobox's Items collection:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
ComboBox1.SelectedIndex = 0
End Sub
"VB User" wrote:
Is there some other property I should set. Setting Selected Index does not
help. It simply reads the text property I set during design time.
"vvenk" wrote:
Set the Combo Box's Selected Index to 0 in the formload event.

Venkat

"VB User" wrote:
I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.
How do I do it?
Thanks

Nov 21 '05 #4
Can you show the code you are using to "read" the selected item?

you need to use combobox1.selecteditem and then read your string from there.

chris
"VB User" <VB****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Is there some other property I should set. Setting Selected Index does
not
help. It simply reads the text property I set during design time.
"vvenk" wrote:
Set the Combo Box's Selected Index to 0 in the formload event.

Venkat

"VB User" wrote:
> I would like the text property of combo box to read the first item of
> the
> list on form load. I have a set of four items in the collection.
> How do I do it?
> Thanks
>

Nov 21 '05 #5
ComboBox1.Text = ComboBox1.Items(0).ToString
cboDPI.SelectedIndex = 0

Both these statements don't work. Any help?

"Chris" wrote:
Can you show the code you are using to "read" the selected item?

you need to use combobox1.selecteditem and then read your string from there.

chris
"VB User" <VB****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Is there some other property I should set. Setting Selected Index does
not
help. It simply reads the text property I set during design time.
"vvenk" wrote:
Set the Combo Box's Selected Index to 0 in the formload event.

Venkat

"VB User" wrote:

> I would like the text property of combo box to read the first item of
> the
> list on form load. I have a set of four items in the collection.
> How do I do it?
> Thanks
>


Nov 21 '05 #6
Um, This is what I think you are trying to do. You have a combobox called
cboDPI. You want the text in the box to display the first item in the list.
You are populating the list with strings. If this is what you are trying to
do, then this is the code you need in the form load event.

cboDPI.Items.Add("audi")
cboDPI.Items.Add("buick")
cboDPI.Items.Add("chevy")
cboDPI.Items.Add("ford")
cboDPI.SelectedIndex = 0

now audi will show up as the selecteditem. If you want to read that item
later in code do:

MessageBox.Show(CStr(cboDPI.SelectedItem))

Good Luck
Chris
"VB User" <VB****@discussions.microsoft.com> wrote in message
news:D6**********************************@microsof t.com...
ComboBox1.Text = ComboBox1.Items(0).ToString
cboDPI.SelectedIndex = 0

Both these statements don't work. Any help?

"Chris" wrote:
Can you show the code you are using to "read" the selected item?

you need to use combobox1.selecteditem and then read your string from
there.

chris
"VB User" <VB****@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
> Is there some other property I should set. Setting Selected Index does
> not
> help. It simply reads the text property I set during design time.
>
>
> "vvenk" wrote:
>
>> Set the Combo Box's Selected Index to 0 in the formload event.
>>
>> Venkat
>>
>> "VB User" wrote:
>>
>> > I would like the text property of combo box to read the first item
>> > of
>> > the
>> > list on form load. I have a set of four items in the collection.
>> > How do I do it?
>> > Thanks
>> >


Nov 21 '05 #7
"VB User" <VB****@discussions.microsoft.com> schrieb:
I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.


Set the control's 'SelectedIndex' property to 0.

If you don't want the user to be able to type text into the combobox (which
is true for most cases), set the combobox's 'DropDownStyle' property to
'DropDownList'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #8
Thanks everyone for the info, it works.

"Herfried K. Wagner [MVP]" wrote:
"VB User" <VB****@discussions.microsoft.com> schrieb:
I would like the text property of combo box to read the first item of the
list on form load. I have a set of four items in the collection.


Set the control's 'SelectedIndex' property to 0.

If you don't want the user to be able to type text into the combobox (which
is true for most cases), set the combobox's 'DropDownStyle' property to
'DropDownList'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #9

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

Similar topics

1
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command...
2
by: MLH | last post by:
Combo box LimitToList property setting of No does not prevent the MS Access error "The text you enter must match an entry in the list" from popping up. What makes this bad is that the error is not...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
4
by: Mark L. Breen | last post by:
Hello Guys and Galls, I use combos on my forms. The code to initialise the combos is as follows Dim dsPIDTypes As DataSet dsPIDTypes = PartDB.GetPIDTypes ' Returns a dataset object...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
6
by: Smokey Grindle | last post by:
Say I have a combo box with the following simple object Public class MyObject public ID as integer public Name as string public overrides sub ToString() as string return name end sub end...
2
by: Brad Pears | last post by:
In my vb.net 2005 project I have a few combo boxes where I want to set a default value. I am not binding these combo boxes - I am loading the values directly in code from a dataset. Obviously...
7
by: Brad Pears | last post by:
I have something strange going on - pretty sure it used to work before - and now it does not... Why does the following code not clear a combo box? Me.cboLocation.Text = String.Empty OR ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
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
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...

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.