CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ComboBox

  1. #1
    Join Date
    Sep 2010
    Posts
    24

    ComboBox

    I have a combobox with whose contents get populated via code. Works ok. But When I select something in the list and hit 'OK' it always returns as: nothing, "", or -1 (tried with .selectedValue, .SelectedText, and .SelectedIndex respectively)

    Question is, How do you access the text in a ComboBox's selected Value??

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: ComboBox

    Download the samples from my signature.

    It should help...
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2010
    Posts
    24

    Re: ComboBox

    Looking at the ListboxCombobox sample. I don't get it, that appears to be exactly what I have. The only difference is my code for that part is located in a module, and I have to refer to my main form
    eg:
    Code:
    var = frmMain.cboDropDown.Text.ToString
    still comes back as ""

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: ComboBox

    Did you see this?

    Code:
        Private Sub cboDemo_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDemo.SelectedIndexChanged
            If cboDemo.SelectedIndex > -1 Then
                lblResults.Text = cboDemo.SelectedValue.ToString
            Else
                lblResults.Text = String.Empty
            End If
        End Sub
    Otherwise, set up a PUBLIC function in the form, to return the value, then call it from your module (when the form is loaded)

    GetValue()
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured