|
-
Aug 29th, 2007, 10:49 AM
#1
Thread Starter
Frenzied Member
[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?
-
Aug 29th, 2007, 10:51 AM
#2
Re: [2005] ComboBox.SelectedItem won't change
I would have run that code from the Click rather than SelectedIndexChange.
-
Aug 29th, 2007, 11:02 AM
#3
Thread Starter
Frenzied Member
Re: [2005] ComboBox.SelectedItem won't change
 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.
-
Aug 29th, 2007, 11:07 AM
#4
Re: [2005] ComboBox.SelectedItem won't change
can you post more code?
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Aug 29th, 2007, 11:20 AM
#5
Thread Starter
Frenzied Member
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).
-
Aug 29th, 2007, 11:24 AM
#6
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
-
Aug 29th, 2007, 11:27 AM
#7
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
-
Aug 29th, 2007, 11:37 AM
#8
Re: [2005] ComboBox.SelectedItem won't change
 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.
-
Aug 29th, 2007, 11:49 AM
#9
Thread Starter
Frenzied Member
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.
-
Aug 29th, 2007, 11:51 AM
#10
Re: [2005] ComboBox.SelectedItem won't change
 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.
-
Aug 29th, 2007, 12:07 PM
#11
Thread Starter
Frenzied Member
Re: [2005] ComboBox.SelectedItem won't change
 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.... I'll let you know if it ever pops up!
-
Aug 29th, 2007, 12:12 PM
#12
Re: [2005] ComboBox.SelectedItem won't change
 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 ???
-
Aug 29th, 2007, 12:36 PM
#13
Thread Starter
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|