Results 1 to 4 of 4

Thread: Combobox value reset

  1. #1
    Sergionik is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Sep 2010
    Posts
    7
    Reputation
    0

    Combobox value reset

    Hi!

    I use Combobox with property "DropDownStyle=DropDownList"
    Combobox is filled with values, e.g. "Tables", "Queries", "Macros".

    Sometimes I should reset value and I write code:
    PHP Code:
    Combobox1.Text="" 
    But it doesn't work, i.e. if value has been chosen "Queries", after performance of a code value doesn't change
    Where I was mistaken?

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,007
    Reputation
    1628
    The Text property should generally only be used when DropDownStyle is DropDown, in which case it behaves just like the text of a TextBox. If you don't want any item selected in the ComboBox you should set the SelectedItem to Nothing or the SelectedIndex to -1.

  3. #3
    Sergionik is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Sep 2010
    Posts
    7
    Reputation
    0
    Thanks, jmcilhinney!
    It's working.

    And I have thought up an alternative variant...
    As Combobox obtains the data from the table I have added in the table record "- - isn't chosen - -".
    Now, when I should Combobox reset value, I actually choose value "- - isn't chosen - -".

  4. #4
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,007
    Reputation
    1628
    I always find it interesting that so many people want to put a "dummy" entry into a ComboBox yet the same people are more than happy to leave a TextBox empty. If the user can work out that they are supposed to enter something into an empty TextBox, surely they can also work out that they are supposed to select something from an empty ComboBox.

Bookmarks

Posting Permissions

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