Results 1 to 8 of 8

Thread: Read-only combo box

  1. #1

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    47

    Read-only combo box

    What is the the best way to make a combobox which is binded to a datasource read-only. Although the Enabled property works, but it makes the combobox too dim to be able to be visible to end user.
    I realised that there is no Read-only property for combobox.
    Thank You.

  2. #2
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Read-only combo box

    Set the DropdownStyle property to DropDownList.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    47

    Re: Read-only combo box

    Even when I set to dropdownlist, there is no read only property.
    I dun want user to select any thing from the list. That means when they clicked the drop down error, nothing will happen.The combo is only for displayed purpose till they click an edit button which reset the property back to dafault.

  4. #4
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: Read-only combo box

    You may want to use a ListBox instead of a ComboBox. You can set the ListBox's SelectionMode to None so the user cannot select any items.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  5. #5
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Read-only combo box

    If it is for display only, I'd be doing as circuits2 suggests - use a list box or a data grid.

    If you really want to use a combo, you could assign the index of the combo that you want to maintain in the SelectedIndexChanged event:

    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            ComboBox1.SelectedIndex = 2
    End Sub

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

    Re: Read-only combo box

    If the user sees an enabled ComboBox they have a right to expect it to allow them to choose an item. If it doesn't then they have a right to assume that your app is broken. If you don't want the user to make a selection and you don't want to disable the ComboBox (how bad is your user's eyesight that they can't read a disabled ComboBox?) then hide it and display a read-only TextBox in its place.
    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

  7. #7

    Thread Starter
    Member
    Join Date
    May 2007
    Posts
    47

    Re: Read-only combo box

    Quote Originally Posted by robertx
    If it is for display only, I'd be doing as circuits2 suggests - use a list box or a data grid.

    If you really want to use a combo, you could assign the index of the combo that you want to maintain in the SelectedIndexChanged event:

    Code:
    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
            ComboBox1.SelectedIndex = 2
    End Sub
    If the data inside the combo box is grab from a database, combobox1.selectedindex=0 or 1 or 2 doesn't seems to get any value

  8. #8
    Frenzied Member
    Join Date
    Jan 2001
    Posts
    1,374

    Re: Read-only combo box

    You will need to refer to the index of the item in your datasource. For example, if you want to display data relating to the fourth record in your datasource then set the SelectedIndex to 3.

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