Results 1 to 3 of 3

Thread: [RESOLVED] ComboBox Behaviour

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Resolved [RESOLVED] ComboBox Behaviour

    I have a comboBox with items that are added or deleted at runtime.
    Sometimes I need the combobox to display "Varies" where no specific selection applies.

    A normal comboBox highlights the text once you click it but you can then highlight portions or set the cursor at a specific position in the text.

    I currently add a Click event to remove "Varies".

    HTML Code:
        Private Sub ComboBox1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.Click
            If ComboBox1.Items.Contains("Varies") Then ComboBox1.Items.Remove("Varies") 
        End Sub
    But
    1: This disables this normal functionality. Everytime I click it highlights the full text.
    2: If I press escape without selecting another item it returns the combobox.text as "" which I really need to go as unhandled and revert to "Varies"

    Hope someone can help.

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

    Re: ComboBox Behaviour

    Is the DropDownStyle set to DropDown or DropDownList? Which do you want it set to? The former allows you to enter text that does not correspond to an item while the latter will only accept an in-list selection. If you want to just be able to set the Text to "Varies" without that being an item, use the former.
    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

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Re: ComboBox Behaviour

    Hi jmcilhinney,

    I use both.
    Your reply made me understand that my question was about two problems that were specific to each type of combobox you mention.
    Dropdown I should be simply adding "Varies" as text, and not an item, and solves the first question.
    DropDownList I'll need to re add "Varies" if the user presses escape without making a valid selection.
    Thanks again!

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