By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,558 Members | 1,673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,558 IT Pros & Developers. It's quick & easy.

ComboBox Question

P: n/a
I provide a bunch of items at form load for the combo box.

What I want to do is if the user chooses to enter a value not in the item
list I want to be able to grab that and assign it to a string variable.

is this possible?

Nov 20 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Hello,

"scorpion53061" <sc************@yahoo.com> schrieb:
I provide a bunch of items at form load for the combo box.

What I want to do is if the user chooses to enter a value not
in the item list I want to be able to grab that and assign it
to a string variable.


You can use the combobox's 'FindString' and 'FindStringExact' methods to
check if a string is contained in the item list.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #2

P: n/a
drnew.Item("TYPE") = ComboBox1.Text.ToString

This doesnt add what the user put in the combo box.

What do you think would?

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:O7**************@TK2MSFTNGP10.phx.gbl...
Hello,

"scorpion53061" <sc************@yahoo.com> schrieb:
I provide a bunch of items at form load for the combo box.

What I want to do is if the user chooses to enter a value not
in the item list I want to be able to grab that and assign it
to a string variable.


You can use the combobox's 'FindString' and 'FindStringExact' methods to
check if a string is contained in the item list.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #3

P: n/a
Cor
Scorpion
I should try to put it in a messagebox first to test it
For me it works
drnew.Item("TYPE") = ComboBox1.Text.ToString

messagebox.show(combobox1.text.toString)

I hope this helps you a little bit.
Cor
Nov 20 '05 #4

P: n/a
Hello,

"scorpion53061" <sc************@yahoo.com> schrieb:
drnew.Item("TYPE") = ComboBox1.Text.ToString
You don't need to call 'ToString' here, 'Text' will return a string.
This doesnt add what the user put in the combo box.


What is 'drnew'? Are you working with a databound combobox?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

P: n/a
Nak
> drnew.Item("TYPE") = ComboBox1.Text.ToString

This doesnt add what the user put in the combo box.


Are you wanting to add to the same combo box that the user has selected
from? To add items to a combo box you need to use the add method of the
items collection...

combobox1.Items.Add("my string")

But when do you want to add to the combo box? After the user has finished
typing? Remember there is no way to know if the user has *finished* typing
as such unless you actually use a timer, which is a bit of a fudge. Maybe
check for the enter key being pressed in the keydown event?

Private Sub ComboBox1_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyDown
If (e.KeyCode = Keys.Enter) Then
If (ComboBox1.FindStringExact(ComboBox1.Text) = -1) Then
Call ComboBox1.Items.Add(ComboBox1.Text)
End If
End If
End Sub

But then again I might have the wrong idea about what you want?

Nick.

--
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
"No matter. Whatever the outcome, you are changed."

Fergus - September 5th 2003
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
Nov 20 '05 #6

P: n/a
Hi Herfried,

drnew = drNew = datarowNew ;-)

Regards,
Fergus
Nov 20 '05 #7

P: n/a
Correct herfried......
I am trying to add the combobox control's text as a entry in a dataset even
if the user had changed it.

"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:ep*************@tk2msftngp13.phx.gbl...
Hello,

"scorpion53061" <sc************@yahoo.com> schrieb:
drnew.Item("TYPE") = ComboBox1.Text.ToString


You don't need to call 'ToString' here, 'Text' will return a string.
This doesnt add what the user put in the combo box.


What is 'drnew'? Are you working with a databound combobox?

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #8

P: n/a
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
drnew = drNew = datarowNew ;-)


That's what I thought, but I was not sure.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.