VS 2010 ComboBox Help-VBForums
Results 1 to 2 of 2

Thread: ComboBox Help

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    226

    Question ComboBox Help

    How to I have an if statement depending on the combo box selection? I get this message:
    Conversion from string "Clear" to type 'Double' is not valid.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            If ComboBox1.SelectedIndex = "Clear" Then
                TextBox1.Clear()
            ElseIf ComboBox1.SelectedIndex = "Disable" Then
                TextBox1.Enabled = False
            ElseIf ComboBox1.SelectedIndex = "Both" Then
                TextBox1.Clear()
                TextBox1.Enabled = False
            End If
        End Sub
    Thanks in advance for the help.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: ComboBox Help

    The SelectedIndex property returns the index of the selected item, which is an Integer N in the range 0 <= N < Items.Count. If you want the actual text displayed in the control then use the Text property. You might also use the SelectedItem or SelectedValue property, which may both contain the same value as the Text property but may not, depending on the circumstances.

    By the way, you would also be better to use a Select Case statement than If...ElseIf in that situation.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.