Results 1 to 13 of 13

Thread: [RESOLVED] [2005] ComboBox.SelectedItem won't change

  1. #1

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Resolved [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?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [2005] ComboBox.SelectedItem won't change

    I would have run that code from the Click rather than SelectedIndexChange.

  3. #3

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  4. #4
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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

  5. #5

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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:
    1. Public Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SubmitButton.Click
    2.  
    3.      With myJob       ' myJob is a custom class
    4.  
    5.            ' AssignMin is a String variable.
    6.            .AssignMin = CType(Me.AssignMinComboBox.SelectedItem, String)
    7.  
    8.      End With
    9.  
    10. End Sub


    I tried using this:

    vb Code:
    1. .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).
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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

  7. #7
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  9. #9

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  11. #11

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.... I'll let you know if it ever pops up!
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  12. #12
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

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

  13. #13

    Thread Starter
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    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.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width