SunQuest
 
           Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 9th, 2004, 01:59 AM
digitalscream digitalscream is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Canada
Posts: 3 digitalscream User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Automatically selecting text in a ComboBox Dropdown List

I created a combo box with the Dropdown List style property because I essentially want to restrict the user to enter only specified items.

I use the following code to select specific text in a combo box but it seems like there is a better way. This method is slow and you can see the combo box scroll through the items on a slow computer. Any help is appreciated. Thanks in advance for you time!

Code:
Public Function GetPC(ByVal strText As String) As Integer
 
 	Dim i As Integer
 	
 	With frmMain.cboPriority
 		For i = 0 To .ListCount
 			.ListIndex = i
 			If .Text = strText Then
 				GetPC = i
 				Exit Function
 			End If
 		Next i
 	End With
 
 End Function


I use the following code to call this function...

Code:
cboPriority.ListIndex = GetPC(rstAccounts!PC)


I tried to write to the .Text property of the list box hoping that it would select the item matching the text I specify but it gives me a run-time error. I found that I can only read the .Text propery at run-time when the Dropdown list style is used.

Thanks,
Luke

Reply With Quote
  #2  
Old August 10th, 2004, 10:41 AM
Mythomep Mythomep is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Zaandam, The Netherlands
Posts: 70 Mythomep User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 m 37 sec
Reputation Power: 4
Send a message via MSN to Mythomep
Hi,

There is one quick solution for your problem. There is also a more extensive solution, that encourages reuse of the combobox acros multiple forms (or even projects). But I take it you want the short quick solution.

Try the following code:

Code:
lResult = winSendMessageS(cboCombobox.hwnd, CB_FINDSTRING, -1, "Text to find")
cboCombobox.Listindex = lResult


This is an api call that will tell the combobox to look in its contents for the string. Below are the declarations for the api calls:

Code:
Public Declare Function winSendMessageS Lib "user32" Alias "SendMessageA" _
				 (ByVal hwnd As Long, _
				 ByVal wMsg As Long, _
				 ByVal wParam As Long, _
				 ByVal lParam As String) As Long

Public Const CB_FINDSTRING = &H14C
Public Const CB_FINDSTRINGEXACT = &H158


The CB_FINDSTRINGEXACT will cause the combobox to search case sensitive. The other CB_FINDSTRING does not care about case.

If you want a better solution, you might make a usercontrol that contains the combobox and wrap the needed methods and properties in the usercontrol. If you want an example, I could post it here but it is alot of code. I use this solution for all my comboboxes I need in applications and reuse existing ones when I need the same combobox in another program. But that is entirely up to you. The Api call works just as well.

If you have any questions, feel free to ask them.

Grtz.©

M.

Reply With Quote
  #3  
Old August 10th, 2004, 10:57 AM
digitalscream digitalscream is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Location: Canada
Posts: 3 digitalscream User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the reply! Much appreciated.

-Luke

Reply With Quote
  #4  
Old October 29th, 2004, 08:01 AM
Kopano123 Kopano123 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 Kopano123 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Red face Automatically selecting text in a ComboBox Dropdown List

Quote:
Originally Posted by digitalscream
Thanks for the reply! Much appreciated.

-Luke


hi all,

I have a similar problem with combo boxes. I want to dynamically link more than 2 combo boxes, i.e. when i change a selection in one combobox, the 2nd combobox gives a corresponding list, and when i change selection in the 2nd combobox, the third box gives another corresponding list. any ideas on this?

Reply With Quote
  #5  
Old October 29th, 2004, 11:38 AM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 18 h 33 m 48 sec
Reputation Power: 180
Don't add to a long-dead thread, post your own question topic.

Look at the onChange or lostFocus events to fire code that changes other combo lists.
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Automatically selecting text in a ComboBox Dropdown List


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway