[RESOLVED] [2005] ComboBox.SelectedItem won't change
This is annoying me to no end.
Code:
Public Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.TextBox1.Text = Me.ComboBox1.SelectedItem.ToString()
End Sub
The value of TextBox1.Text is always equal to ComboBox1.Item(0) regardless of what item is selected in the ComboBox. The DropDownStyle is set to DropDownList.
Any ideas?
Re: [2005] ComboBox.SelectedItem won't change
I would have run that code from the Click rather than SelectedIndexChange.
Re: [2005] ComboBox.SelectedItem won't change
Quote:
Originally Posted by Hack
I would have run that code from the Click rather than SelectedIndexChange.
I just used that as an example. I have several routines that refer to the currently selected item in the ComboBox, but SelectedItem.ToString always returns the string value of Item(0), regardless of what item is selected.
Re: [2005] ComboBox.SelectedItem won't change
can you post more code?
kevin
Re: [2005] ComboBox.SelectedItem won't change
There really isn't much more to the code than a variation of what is given.
This was the original:
vb Code:
Public Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
With myJob ' myJob is a custom class
' AssignMin is a String variable.
.AssignMin = CType(Me.AssignMinComboBox.SelectedItem, String)
End With
End Sub
I tried using this:
vb Code:
.AssignMin = Me.AssignMinComboBox.SelectedItem.ToString()
But I got the same results. AssignMin always equals the string value of Item 0, event if the SelectedIndex is 1 (I tested this with a message box).
Re: [2005] ComboBox.SelectedItem won't change
This worked for me
Code:
Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Click
Label1.Text = ComboBox1.SelectedIndex.ToString()
End Sub
Re: [2005] ComboBox.SelectedItem won't change
Hack - I'm curious as to how that would work for the mouse-challenged users who like to use their keyboards for everything. Does the click still fire when a selection is made?
-tg
Re: [2005] ComboBox.SelectedItem won't change
Quote:
Originally Posted by techgnome
Hack - I'm curious as to how that would work for the mouse-challenged users who like to use their keyboards for everything. Does the click still fire when a selection is made?
-tg
No....for all possibilities you would want to code the keypress in case they arrowed through the combo and hit enter, and I used the SelectedValueChanged event to fire the code by just arrow keying through the combo and the index was displayed in the label.
Re: [2005] ComboBox.SelectedItem won't change
The documentation for the Click event says that it is fired if the enter key is pressed when the control has focus.
Re: [2005] ComboBox.SelectedItem won't change
Quote:
Originally Posted by circuits2
The documentation for the Click event says that it is fired if the enter key is pressed when the control has focus.
Put a messagebox in the click event just to display "Hi"
You can wail away all day long on the enter key and that box won't ever show up. :)
Re: [2005] ComboBox.SelectedItem won't change
Quote:
Originally Posted by Hack
Put a messagebox in the click event just to display "Hi"
You can wail away all day long on the enter key and that box won't ever show up. :)
I'm still tapping ENTER.... :D I'll let you know if it ever pops up!
Re: [2005] ComboBox.SelectedItem won't change
Quote:
Originally Posted by circuits2
This is annoying me to no end.
Code:
Public Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Me.TextBox1.Text = Me.ComboBox1.SelectedItem.ToString()
End Sub
The value of TextBox1.Text is always equal to ComboBox1.Item(0) regardless of what item is selected in the ComboBox. The DropDownStyle is set to DropDownList.
Any ideas?
This works for me... So I guess either the event somehow doesn't fire, or ???
Re: [RESOLVED] [2005] ComboBox.SelectedItem won't change
Resolution:
Step 1: Open Tool Box
Step 2: Remove 3lb Hammer
Step 3: Commence beating self over head with hammer
Step 4: Realize that you assigned variable to wrong db field after XMLSerialization.