CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2001
    Posts
    49

    Combo Box Text Max Length

    Is there a way to set the max length in a combo box?

    Like the TextBox.Max property, if the user types in the text field, it would stop at the max length. There is no such property for combobox, can it be added by a SendMessage API or a wrapper?

    Thanks.


  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Combo Box Text Max Length

    Simply limit text length in the Keypress event like so

    option Explicit


    private Sub Combo1_KeyPress(KeyAscii as Integer)
    If len(Combo1.Text) > 5 then KeyAscii = 0

    End Sub




    John G

  3. #3
    Join Date
    Sep 2001
    Posts
    49

    Re: Combo Box Text Max Length

    Does not work correctly. Yes it stops the character from printing but can't use other keys like backspace unless you change focus with the mouse. But thanks for the tip I was able to work around it.


  4. #4
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Combo Box Text Max Length

    [vbcode]
    private Sub Combo1_KeyPress(KeyAscii as Integer)
    If len(Combo1.Text) > 5 and KeyAscii <> 8 then
    KeyAscii = 0
    End Sub

    Will let the Backspace in


    Nicolas Bohemier
    ______________

    Un sourire ne coûte rien, mais il rapporte beaucoup; il enrichit celui qui le reçoit sans appauvrir celui qui le donne.

    Frank Irving Fletcher

    Nicolas Bohemier

  5. #5
    Join Date
    Sep 2001
    Location
    Montreal Canada
    Posts
    1,080

    Re: Combo Box Text Max Length


    private Sub Combo1_KeyPress(KeyAscii as Integer)
    If len(Combo1.Text) > 5 and KeyAscii <> 8 then
    KeyAscii = 0
    End Sub




    Will let the Backspace in


    Nicolas Bohemier
    ______________

    Un sourire ne coûte rien, mais il rapporte beaucoup; il enrichit celui qui le reçoit sans appauvrir celui qui le donne.

    Frank Irving Fletcher

    Nicolas Bohemier

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

Featured