Click to See Complete Forum and Search --> : Combo Box Text Max Length


DeafBug
October 19th, 2001, 12:49 PM
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.

John G Duffy
October 19th, 2001, 03:50 PM
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

DeafBug
November 13th, 2001, 02:23 PM
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.

Boumxyz2
November 13th, 2001, 02:51 PM
[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

Boumxyz2
November 13th, 2001, 02:52 PM
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