Results 1 to 3 of 3

Thread: Begginer question about Combobox

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 1999
    Location
    Murcia
    Posts
    13

    Post

    I‘m using VB6.0 and I have a combobox to introduce the year. I want to limit the numer of characters to 4.
    Is there any property similar to Maxlength (textbox)in a Combobox.??
    Does anybdoy know how to limit the number of characteres to introduce in a Combobox.??

    Any advice will be greatly apreciatted.

    Thank you very much

  2. #2
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    There's no direct property to do that, BUT...
    You can check the lenght of the text in the EditBox of the ComboBox and if it is 4 then don't allow the user to enter anything else:

    Put this on ComboBox KeyPress event:

    Code:
    Private Sub Combo1_KeyPress(KeyAscii As Integer)
        If Len(Combo1.Text) >= 4 And KeyAscii <> vbKeyBack Then
            KeyAscii = 0
        End If
    End Sub
    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


  3. #3
    Member
    Join Date
    Dec 1999
    Posts
    37

    Post

    You can use SendMessage and CB_LIMITTEXT to simulate MaxLength in a Combo's Edit Box.

    Put the following code in the BAS module

    Code:
    Option Explicit
    
    Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
    Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Const CB_LIMITTEXT = &H141
    Place the ComboBox and a command button on the form. Add the following code.

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Dim imaxlength As Integer
        
        imaxlength = 6
        
        Call SetWindowText(Combo1.hwnd, "")
        
        Call SendMessageLong(Combo1.hwnd, CB_LIMITTEXT, imaxlength, 0&)
    End Sub
    Ruchi

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