PDA

Click to See Complete Forum and Search --> : Begginer question about Combobox


Nauj
Dec 6th, 1999, 04:49 PM
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

Serge
Dec 6th, 1999, 05:54 PM
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:


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
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)

Ruchi
Dec 8th, 1999, 12:15 AM
You can use SendMessage and CB_LIMITTEXT to simulate MaxLength in a Combo's Edit Box.

Put the following code in the BAS module


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.


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