Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to make a non-editable Combo-box?

How to make a non-editable Combo-box?

Scheduled Pinned Locked Moved C#
csharpquestionhelptutorial
10 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PravinSingh
    wrote on last edited by
    #1

    Sorry to ask such a basic question, actually I'm new to C#. I want to have a non-editable combo-box on my form (where user can choose from the items, but can not edit/type a new item into the combo. The .net 2005 forms editor gives me 2 choices (i) Create a list-box, which I don't want, as I need a drop-down (ii) Create a Combo-box, but that is always editable. In VS6, we could create a combo and then in its properties we could choose the type to be list box, but I could not find any such property in C#. Any help is appreciated.


    It's better to know some of the questions than all of the answers.
    Pravin.

    G S N 3 Replies Last reply
    0
    • P PravinSingh

      Sorry to ask such a basic question, actually I'm new to C#. I want to have a non-editable combo-box on my form (where user can choose from the items, but can not edit/type a new item into the combo. The .net 2005 forms editor gives me 2 choices (i) Create a list-box, which I don't want, as I need a drop-down (ii) Create a Combo-box, but that is always editable. In VS6, we could create a combo and then in its properties we could choose the type to be list box, but I could not find any such property in C#. Any help is appreciated.


      It's better to know some of the questions than all of the answers.
      Pravin.

      S Offline
      S Offline
      sepel
      wrote on last edited by
      #2

      :rose:DropdownStyle=DropDwonList

      sepel

      G 1 Reply Last reply
      0
      • P PravinSingh

        Sorry to ask such a basic question, actually I'm new to C#. I want to have a non-editable combo-box on my form (where user can choose from the items, but can not edit/type a new item into the combo. The .net 2005 forms editor gives me 2 choices (i) Create a list-box, which I don't want, as I need a drop-down (ii) Create a Combo-box, but that is always editable. In VS6, we could create a combo and then in its properties we could choose the type to be list box, but I could not find any such property in C#. Any help is appreciated.


        It's better to know some of the questions than all of the answers.
        Pravin.

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        Use DropDownStyle property of combobox class.

        Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

        P 1 Reply Last reply
        0
        • G Giorgi Dalakishvili

          Use DropDownStyle property of combobox class.

          Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

          P Offline
          P Offline
          PravinSingh
          wrote on last edited by
          #4

          Thank you guys for the quick help :)


          It's better to know some of the questions than all of the answers.
          Pravin.

          G 1 Reply Last reply
          0
          • P PravinSingh

            Thank you guys for the quick help :)


            It's better to know some of the questions than all of the answers.
            Pravin.

            G Offline
            G Offline
            Giorgi Dalakishvili
            wrote on last edited by
            #5

            You are welcome :)

            Giorgi Dalakishvili #region signature my articles My blog[^] #endregion

            1 Reply Last reply
            0
            • P PravinSingh

              Sorry to ask such a basic question, actually I'm new to C#. I want to have a non-editable combo-box on my form (where user can choose from the items, but can not edit/type a new item into the combo. The .net 2005 forms editor gives me 2 choices (i) Create a list-box, which I don't want, as I need a drop-down (ii) Create a Combo-box, but that is always editable. In VS6, we could create a combo and then in its properties we could choose the type to be list box, but I could not find any such property in C#. Any help is appreciated.


              It's better to know some of the questions than all of the answers.
              Pravin.

              N Offline
              N Offline
              nelsonpaixao
              wrote on last edited by
              #6

              do this

              private void MyComboBox_KeyPress(object sender, KeyPressEventArgs e)
              {
              if (e.KeyChar < 256)
              e.Handled = true;
              }

              ;P user can´t press any key! just select You may try also use this for textboxes that you want to get just numbers (and backspace key)

              private void MyTextBox_KeyPress(object sender, KeyPressEventArgs e)
              {
              if ((e.KeyChar < 48) || (e.KeyChar > 57))
              e.Handled = true;
              if (e.KeyChar == 8)
              e.Handled = false;
              }

              As you see this way you can avoid doind some validations like try{}catch{} Learn the ascii code to know the keys you are allowing or not :rolleyes:

              nelsonpaixao@yahoo.com.br trying to help & get help

              D 1 Reply Last reply
              0
              • N nelsonpaixao

                do this

                private void MyComboBox_KeyPress(object sender, KeyPressEventArgs e)
                {
                if (e.KeyChar < 256)
                e.Handled = true;
                }

                ;P user can´t press any key! just select You may try also use this for textboxes that you want to get just numbers (and backspace key)

                private void MyTextBox_KeyPress(object sender, KeyPressEventArgs e)
                {
                if ((e.KeyChar < 48) || (e.KeyChar > 57))
                e.Handled = true;
                if (e.KeyChar == 8)
                e.Handled = false;
                }

                As you see this way you can avoid doind some validations like try{}catch{} Learn the ascii code to know the keys you are allowing or not :rolleyes:

                nelsonpaixao@yahoo.com.br trying to help & get help

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                This won't handle the case of somebody using the mouse to paste data or cutting data for that matter. The solutions given previously are what the OP needed in his situation. In the more general scenario that you're preempting, to be successful you need to at least ... override OnKeyDown override OnTextChanged override WndProc and trap WM_PASTE and WM_CUT ... being careful to allow navigation keys like Home, End, Tab, Shift+Tab and the arrow keys if appropriate. If you just disable all keys the UI becomes very non-standard and the user will hate you and your software! ;)

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                N P 2 Replies Last reply
                0
                • D DaveyM69

                  This won't handle the case of somebody using the mouse to paste data or cutting data for that matter. The solutions given previously are what the OP needed in his situation. In the more general scenario that you're preempting, to be successful you need to at least ... override OnKeyDown override OnTextChanged override WndProc and trap WM_PASTE and WM_CUT ... being careful to allow navigation keys like Home, End, Tab, Shift+Tab and the arrow keys if appropriate. If you just disable all keys the UI becomes very non-standard and the user will hate you and your software! ;)

                  Dave
                  BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                  Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                  N Offline
                  N Offline
                  nelsonpaixao
                  wrote on last edited by
                  #8

                  i see what you mean, i didn´t knew that, i learn it westerday :doh: sometimes we waste time (and code) in simply thinks!!! X| waste of time but works. The way i used, i learned it last year so i think (not sure) that you couldn´t use that dropdownlist propriety in c# 2005! So i drop it but still i have to use it in other cases (like textboxes the only accept numbers for exemple). (I am using it in a combobox also because i can´t handle, by now, that propriety for a particulat task. Maybe my next post ;P )

                  nelsonpaixao@yahoo.com.br trying to help & get help

                  1 Reply Last reply
                  0
                  • D DaveyM69

                    This won't handle the case of somebody using the mouse to paste data or cutting data for that matter. The solutions given previously are what the OP needed in his situation. In the more general scenario that you're preempting, to be successful you need to at least ... override OnKeyDown override OnTextChanged override WndProc and trap WM_PASTE and WM_CUT ... being careful to allow navigation keys like Home, End, Tab, Shift+Tab and the arrow keys if appropriate. If you just disable all keys the UI becomes very non-standard and the user will hate you and your software! ;)

                    Dave
                    BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                    Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)

                    P Offline
                    P Offline
                    PravinSingh
                    wrote on last edited by
                    #9

                    Thank you DaveyM69 for the tip. Although the solution proposed by nelsonpaixao is not what I was looking for and my current need is perfectly addressed by making DropdownStyle=DropDwonList, I will keep this solution in mind for some later day, e.g. when I need a textbox that only accepts numbers. Thank you nelsonpaixao. :)


                    It's better to know some of the questions than all of the answers.
                    Pravin.

                    1 Reply Last reply
                    0
                    • S sepel

                      :rose:DropdownStyle=DropDwonList

                      sepel

                      G Offline
                      G Offline
                      gezanal
                      wrote on last edited by
                      #10

                      ur very helpful!!!thanks for the info.. ;)

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups