ComboBox Question

  • Thread starter Thread starter scorpion53061
  • Start date Start date
S

scorpion53061

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?
 
Hello,

scorpion53061 said:
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.
 
drnew.Item("TYPE") = ComboBox1.Text.ToString

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

What do you think would?
 
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
 
Hello,

scorpion53061 said:
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?
 
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
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
 
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.
 
Back
Top