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

Populating initial Combobox display text

Hello - this started out as a minor annoyance - and now is
starting to bother me more and more - I'm hoping someone
can help me.

I would like to have a combobox display - NOT initially be
blank - but contain a value. However the value is just
for user reference - not really one of the combobox
choices. For example intially the combobox should equal
the word Select - and the item values can be
say 'one', 'two', and 'three'.

I tried just typing in the text value - in the properties
of the combobox control/object - but that did not work.
Someone told me in order to display the value - it has to
be an existing part of the collection. Doesn't completely
make sense to me - because why have a Text properties
field of the control - if you can't use it (everytime you
fill something in - and leave that field - it's blanked
out)

So what I ended up doing was - adding the item to the:
Windows Form Designer Generated Code Section - something
like this:

Me.ComboBox1.Items.Add("Select")
Me.ComboBox1.Items.Add("one")
Me.ComboBox1.Items.Add("two")
Me.ComboBox1.Items.Add("three")
Me.ComboBox1.Location = New System.Drawing.Point
(8, 25)
Me.ComboBox1.Size = New System.Drawing.Size(220,
22)
Me.ComboBox1.Text = "Select"

Well - it works - but here's the real problem. Every now
and then (I think when I click on that combobox - or even
on the form somehow - to open the design) - it removes the
last line: Me.ComboBox1.Text = "Select".

So - sometimes I compile - and I get "Select" as the
initial default value for the combobox and other times - I
do not and I have to re-add it. Sure - minor annoyance -
but when you have to do this 10, 20, 30, 50 times - it
becomes a MAJOR annoyance.

Am I doing something wrong?
Can someone suggest a better way?
Thank you.
Nov 20 '05 #1
4 3965
Sounds like you are trying to do a webpage type thing of having a value that
isn't in the list.

Looks like to me that if the style of the combobox is such that you can edit
the text, setting the text property should be allowed?

Of course if the style is one of the other types it of course won't let you
do this. Have you tried it with the correct style?

Shane
"Keith" <an*******@discussions.microsoft.com> wrote in message
news:20*****************************@phx.gbl...
Hello - this started out as a minor annoyance - and now is
starting to bother me more and more - I'm hoping someone
can help me.

I would like to have a combobox display - NOT initially be
blank - but contain a value. However the value is just
for user reference - not really one of the combobox
choices. For example intially the combobox should equal
the word Select - and the item values can be
say 'one', 'two', and 'three'.

I tried just typing in the text value - in the properties
of the combobox control/object - but that did not work.
Someone told me in order to display the value - it has to
be an existing part of the collection. Doesn't completely
make sense to me - because why have a Text properties
field of the control - if you can't use it (everytime you
fill something in - and leave that field - it's blanked
out)

So what I ended up doing was - adding the item to the:
Windows Form Designer Generated Code Section - something
like this:

Me.ComboBox1.Items.Add("Select")
Me.ComboBox1.Items.Add("one")
Me.ComboBox1.Items.Add("two")
Me.ComboBox1.Items.Add("three")
Me.ComboBox1.Location = New System.Drawing.Point
(8, 25)
Me.ComboBox1.Size = New System.Drawing.Size(220,
22)
Me.ComboBox1.Text = "Select"

Well - it works - but here's the real problem. Every now
and then (I think when I click on that combobox - or even
on the form somehow - to open the design) - it removes the
last line: Me.ComboBox1.Text = "Select".

So - sometimes I compile - and I get "Select" as the
initial default value for the combobox and other times - I
do not and I have to re-add it. Sure - minor annoyance -
but when you have to do this 10, 20, 30, 50 times - it
becomes a MAJOR annoyance.

Am I doing something wrong?
Can someone suggest a better way?
Thank you.

Nov 20 '05 #2
HI Keith,

I think that your problem has to do with one of the few documentated on MSDE
documented bugs in the combobox.

However even beside that I think this would be a better solution for you
problem (I made this sample for you so you have to try it).

I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.SelectedIndex = 0
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownList
End Sub
Private Sub ComboBox1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles _
ComboBox1.SelectedIndexChanged
If Me.ComboBox1.Text <> "Select" Then
'do something
End If
Me.ComboBox1.SelectedIndex = 0
End Sub
///
Hello - this started out as a minor annoyance - and now is
starting to bother me more and more - I'm hoping someone
can help me.

I would like to have a combobox display - NOT initially be
blank - but contain a value. However the value is just
for user reference - not really one of the combobox
choices. For example intially the combobox should equal
the word Select - and the item values can be
say 'one', 'two', and 'three'.

I tried just typing in the text value - in the properties
of the combobox control/object - but that did not work.
Someone told me in order to display the value - it has to
be an existing part of the collection. Doesn't completely
make sense to me - because why have a Text properties
field of the control - if you can't use it (everytime you
fill something in - and leave that field - it's blanked
out)

So what I ended up doing was - adding the item to the:
Windows Form Designer Generated Code Section - something
like this:

Me.ComboBox1.Items.Add("Select")
Me.ComboBox1.Items.Add("one")
Me.ComboBox1.Items.Add("two")
Me.ComboBox1.Items.Add("three")
Me.ComboBox1.Location = New System.Drawing.Point
(8, 25)
Me.ComboBox1.Size = New System.Drawing.Size(220,
22)
Me.ComboBox1.Text = "Select"

Well - it works - but here's the real problem. Every now
and then (I think when I click on that combobox - or even
on the form somehow - to open the design) - it removes the
last line: Me.ComboBox1.Text = "Select".

So - sometimes I compile - and I get "Select" as the
initial default value for the combobox and other times - I
do not and I have to re-add it. Sure - minor annoyance -
but when you have to do this 10, 20, 30, 50 times - it
becomes a MAJOR annoyance.

Am I doing something wrong?
Can someone suggest a better way?
Thank you.

Nov 20 '05 #3
Cor,

thanks for you code - I tried it - but didn't get the
results I expected. Perhaps I did not accurately state
what I was attempting to do. I wanted to have the Select
text appear - as the initial text of the Combobox - and
then once the person clicked on any of the choices
(besides Select) - the Select code would disappear. I
ended up doing it in the following manner:
(just curious - you mention this combobox bug is well
know - any idea when anyone will "fix" it?)

Keep in mind this code is out there - but it works...
The Combobox Collection is populated with the following
entries: Select, One, and Two
Declare a public variable:
Public firsttimeonlycounter As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
ComboBox1.Text = "Select"
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
If firsttimeonlycounter <> 1 And
ComboBox1.SelectedItem <> "Select" Then
ComboBox1.Items.Remove("Select")
firsttimeonlycounter = 1
End If
End Sub

Thanks again.
-----Original Message-----
HI Keith,

I think that your problem has to do with one of the few documentated on MSDEdocumented bugs in the combobox.

However even beside that I think this would be a better solution for youproblem (I made this sample for you so you have to try it).
I hope this helps?

Cor
\\\
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Me.ComboBox1.SelectedIndex = 0
Me.ComboBox1.DropDownStyle = ComboBoxStyle.DropDownListEnd Sub
Private Sub ComboBox1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles _
ComboBox1.SelectedIndexChanged
If Me.ComboBox1.Text <> "Select" Then
'do something
End If
Me.ComboBox1.SelectedIndex = 0
End Sub
///
Hello - this started out as a minor annoyance - and now is starting to bother me more and more - I'm hoping someone
can help me.

I would like to have a combobox display - NOT initially be blank - but contain a value. However the value is just
for user reference - not really one of the combobox
choices. For example intially the combobox should equal
the word Select - and the item values can be
say 'one', 'two', and 'three'.

I tried just typing in the text value - in the properties of the combobox control/object - but that did not work.
Someone told me in order to display the value - it has to be an existing part of the collection. Doesn't completely make sense to me - because why have a Text properties
field of the control - if you can't use it (everytime you fill something in - and leave that field - it's blanked
out)

So what I ended up doing was - adding the item to the:
Windows Form Designer Generated Code Section - something
like this:

Me.ComboBox1.Items.Add("Select")
Me.ComboBox1.Items.Add("one")
Me.ComboBox1.Items.Add("two")
Me.ComboBox1.Items.Add("three")
Me.ComboBox1.Location = New System.Drawing.Point
(8, 25)
Me.ComboBox1.Size = New System.Drawing.Size(220,
22)
Me.ComboBox1.Text = "Select"

Well - it works - but here's the real problem. Every now and then (I think when I click on that combobox - or even on the form somehow - to open the design) - it removes the last line: Me.ComboBox1.Text = "Select".

So - sometimes I compile - and I get "Select" as the
initial default value for the combobox and other times - I do not and I have to re-add it. Sure - minor annoyance - but when you have to do this 10, 20, 30, 50 times - it
becomes a MAJOR annoyance.

Am I doing something wrong?
Can someone suggest a better way?
Thank you.

.

Nov 20 '05 #4
Hi Keith,

I thought that the problem was that you did want keep the "Select", because
standard when you set in the loadevent (or in the text in the designer)
combobox.text = "Select" that is only showed once

:-)

Cor
Nov 20 '05 #5

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

Similar topics

3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
5
by: keith | last post by:
This may seem simple, but I'm having a bit of trouble figuring out exactly how to do it. I'm accessing a database through an ODBC link, and I have a query that returns only jobs completed that day...
2
by: Robert | last post by:
I'm sure this is a fairly basic question, but I've been looking all over the web for days for suggestions on how to do this. I've got a datagrid that's bound to a dataset on my form. It includes...
2
by: Bill Brinkworth | last post by:
in vb.net 2005, i would like to pull up a name from a database (customers) (i can do this already), then after a name is selected from a combox box, to populate the form's text boxes with with data...
6
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox...
4
by: c_shah | last post by:
I am a beginner and learning VB.net There are two wasy to bind a combobox or a listbox First approach is to assign a datasource and displaymember Second approach is to iterate through datarow...
5
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
0
by: CCLeasing | last post by:
Hello, I have searched google but can not find a straight forward answer to my problem. Hopefuly someone will be kind enough to offer their expertise. Please forgive if this seems a bit convoluted...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.