Oct 27th, 2006, 09:51 PM
#1
Thread Starter
Addicted Member
Oct 27th, 2006, 10:06 PM
#2
Frenzied Member
Re: Really simple ComboBox question
Arby:
I think you need to give us a little more information such as how you are populating your combobox, where is the informatiion coming from, a database, an array, a CSV file, or ???
If you have any code you have written for this, that might also be helpful.
Oct 27th, 2006, 10:12 PM
#3
Thread Starter
Addicted Member
Re: Really simple ComboBox question
Ah, it's just a simple one. For example, imagine a form with one combobox "Combo1", a button "Command1":
Code:
Private Sub Form_Load()
Combo1.additem(A)
Combo1.additem(B)
End Sub
Private Sub Command1_Click()
Combo1.[Something](1)
End sub
Where "[Something]" is the property that I'm looking for.
Basically, the code is for when the form closes, just before Unload (FormName), I want to reset all of the comboboxes to their default values .
Oct 27th, 2006, 10:25 PM
#4
Frenzied Member
Re: Really simple ComboBox question
Arby:
Well, I'm still not sure I understand what you need, but you might try this code:
VB Code:
Private Sub Command1_Click()
Combo1.Text = Combo1.List(Combo1.ListIndex)
End Sub
I'm not sure if that is what you need.???
Oct 27th, 2006, 10:38 PM
#5
Hyperactive Member
Re: Really simple ComboBox question
Oct 27th, 2006, 10:46 PM
#6
Re: Really simple ComboBox question
This may help you.
VB 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
Private Const CB_ERR = (-1)
Private Const CB_FINDSTRING = &H14C
Private Const CB_FINDSTRINGEXACT = &H158
Private Sub Command1_Click()
Dim Strpos As Long
Strpos = FindItemByString(Combo1, "3", True)
If Strpos > -1 Then
Combo1.ListIndex = Strpos
End If
End Sub
Private Function FindItemByString(cmb As ComboBox, ByVal SearchFor As String, Optional FindExact As Boolean = False) As Integer
FindItemByString = CInt(SendMessage(cmb.hwnd, IIf(FindExact, CB_FINDSTRINGEXACT, CB_FINDSTRING), _
CB_ERR, ByVal SearchFor))
End Function
Oct 28th, 2006, 06:09 AM
#7
Thread Starter
Addicted Member
Re: Really simple ComboBox question
AIS4U,binilmb, unfortunately both of those give me " 'Text' Property is read-only" errors, or just don't work (if a list item is selected)
danasegarane - I think that's way more than I need ^_^;;
I've included a code sample. I'm looking to do something really simple, so you're probably overestimating my needs.
In the sample, I've included all three solutions provided above, and some commenting. Feel free to play around and remove bits ^_^
Attached Files
Oct 28th, 2006, 06:15 AM
#8
Hyperactive Member
Re: Really simple ComboBox question
Try This Code...
VB Code:
For i = 0 To Combo1.ListCount - 1
If Combo1.List(i) = "ABC" Then Combo1.ListIndex = i
Next
Oct 28th, 2006, 06:23 AM
#9
Thread Starter
Addicted Member
Re: Really simple ComboBox question
Ah, thanks!
I tested that, and figured out from that code that
Combo1.ListIndex = 0
Was what I was looking for. Thank you!
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width