Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Simple combo box questions


Reply
 
Thread Tools Display Modes
  #1  
Old 05-23-2005, 01:11 AM
cheung cheung is offline
Newcomer
 
Join Date: Jun 2004
Posts: 18
Default Simple combo box questions


Hi,

i have the following simple combo box questions:
1. how can I limit the max length of the input?
2. how can I prevent the user from overtyping the values in the list?

Regards,
Cheung
Reply With Quote
  #2  
Old 05-23-2005, 01:23 AM
Marathon Man's Avatar
Marathon Man Marathon Man is offline
Contributor
 
Join Date: Jan 2004
Location: The "B" Ark
Posts: 458
Default

1. Check the length of the .Text property on _KeyDown
2. Change the .Style to vbComboDropDownList (2)
__________________
"Welcome to IT"
Reply With Quote
  #3  
Old 05-23-2005, 01:34 PM
Lar_19's Avatar
Lar_19 Lar_19 is offline
Senior Contributor

* Expert *
 
Join Date: May 2002
Location: Vancouver, USA
Posts: 999
Default

Another way to simulate a 'MaxLength' property in a combobox would be to set it using the API. Here is an example for you...
Code:
Option Explicit Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _ ByVal hwnd As Long, ByVal wMsg As Long, _ ByVal wParam As Long, lParam As Any) As Long Const CB_LIMITTEXT = &H141 Private Sub Form_Load() ' Pass the maximum number of characters in the wParam of the SendMessage() API ' function. In this example the length will be limited to ten characters. Call SendMessage(Combo1.hwnd, CB_LIMITTEXT, 10, ByVal 0&) End Sub
__________________
1011 0000 1011
Reply With Quote
  #4  
Old 05-24-2005, 12:04 AM
Marathon Man's Avatar
Marathon Man Marathon Man is offline
Contributor
 
Join Date: Jan 2004
Location: The "B" Ark
Posts: 458
Default

Neat.
__________________
"Welcome to IT"
Reply With Quote
  #5  
Old 05-24-2005, 12:13 AM
sindhuKV's Avatar
sindhuKV sindhuKV is offline
Junior Contributor
 
Join Date: Feb 2004
Location: India,Bangalore
Posts: 380
Default

ya cool solution.
it would have been tough to toggle between
KeyDown/Keypress and Style property(DropDownList)
__________________
"If you look at what you do not have in life, you don't have anything, If you look at what you have in life, you have everything."
Reply With Quote
  #6  
Old 05-24-2005, 01:29 PM
Lar_19's Avatar
Lar_19 Lar_19 is offline
Senior Contributor

* Expert *
 
Join Date: May 2002
Location: Vancouver, USA
Posts: 999
Default

Also I should have mentioned that you can remove the restrictions on the length at run-time by making another call and passing zero as the character limit. I found that useful in an app where I wanted to reuse the same combo for multiple purposes with varying requirements for the max length, including no restrictions at all. Basically I just wrote a function that incorporated the call to SendMessage and passed in the combo along with the number of characters needed as it's parameters.
Hope you find this tip useful.
__________________
1011 0000 1011
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->