C# Combobox question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xxsodapopxx5
    New Member
    • Dec 2006
    • 22

    C# Combobox question

    I haven't been coding much... if at all lately and i just picked up some VS2005 C# again and i was wondering if i can make a combobox not be able to change the text in it, like make it read-only... I have taken a while to look it over and I can't figure out the property or code to do it. thanks for your help.
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    You can make its Enabled property to be set to False. This way it stays Read Only !!!
    Cheers

    Comment

    • xxsodapopxx5
      New Member
      • Dec 2006
      • 22

      #3
      ya i tried that already, but i want to be able to still go through the combobox, i just don't want the text changed... sorry if i didn't make it clear in my first post. Thanks again.

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        You might need to work around this.
        Unfortunately it does not have events which can handle changing of indexes.
        You might want to use the indexChanged Event.
        But before that you should create a variable to store the value of the text, and on the Indexchanged event restore the text back to the original one!!

        cheers

        Comment

        • Shashi Sadasivan
          Recognized Expert Top Contributor
          • Aug 2007
          • 1435

          #5
          As i suspected.
          Someone had a solution for it.
          Here you go
          cheers

          Comment

          • xxsodapopxx5
            New Member
            • Dec 2006
            • 22

            #6
            wow sorry it took so long for me to get back to you. I have been really busy with schoolwork... I had stupid essays due... I hate how im taking computer science and i have to take english and history and a whole ton of other crap that has nothing to do with anything... but anyways, thanks alot, i am going to implement this right now.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

              #7
              Ahhh....
              Change the type of your combobox to be restricted to whats inside it.
              It's one of the properties.

              Code:
              mycombobox.DropDownStyle = ComboBoxStyle.DropDownList;
              //does not allow text to be edited

              Comment

              Working...