Results 1 to 10 of 10

Thread: combo boxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    25

    combo boxes

    Hi people

    ive got several combo boxs on a search form and its all working great if you select the items from the list, but have a problem if you type the value, the selectedvalue isnt being returned

    what do i need to do, this is what im using to get the value when selecting via clicking

    Private Sub BTYPE_ComboBox_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTYPE_ComboBox.SelectedIndexChanged
    If Len(Trim(BTYPE_ComboBox.Text)) > 0 Then BTYPE_FILTER.Text = BTYPE_ComboBox.SelectedValue.ToString Else BTYPE_FILTER.Text = 0
    End Sub

    many thanks

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

    Re: combo boxes

    Moved to VB.NET From Database Development As The Question Is More VB Related

    Run the same code in the Keypress is the <Enter> key is pressed after they have finished typing.

    Alternately, don't allow them to type anything into the combo box.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combo boxes

    Using SelectedValue in a ComboBox that accepts direct input doesn't make sense. If you type something in then you haven't selected anything. You should be using Text, not SelectedValue.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    25

    Re: combo boxes

    Hi sorry my fault should of explained better

    the data in the combobox has a numeric value and the display value i.e 98 PUB

    all im after is if they start to type for example pub it then finds that from the list and then validates it to return the value 98

    thanks

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combo boxes

    If you want the user to have to select an item from the list then you should set the DropDownStyle to DropDownList.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    25

    Re: combo boxes

    hi that nearly does what i want only think is it doesnt match as you type it only matches the first letter ie the P

    can you make accept more text as we have alot of different names being able to filter the list more by typing part of the name in really speeds things up, the system was written before in MS access and there comboboxes can do this

    thanks

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combo boxes

    You're going to have to write some code then. You can use the auto-complete functionality built into the control to help but you're going to have to manually select the corresponding item when the user types in a value rather than selecting it from the drop-down list. Note that the control's drop-down list and the auto-complete list are two different things. Also, you'll need to consider what happens if the user types a value that doesn't match an item or matches multiple items.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    25

    Re: combo boxes

    hi do you have any sample code to get me started as im rather stuck

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: combo boxes

    Handle the Validating event, get the Text, find a matching item and select it. If there is no matching item then you'd probably want to set e.Cancel to True to prevent the control losing focus.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Dec 2009
    Posts
    25

    Re: combo boxes

    i final found my problem, my data had extra space after it from where i had import from a old database, the combo box is now working great

    many thanks for the help

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