|
-
Aug 4th, 2000, 04:14 PM
#1
Thread Starter
Hyperactive Member
Hey, this should be baby stuff, but I'm missing something. If I type a value into a combobox, have the code select a value and I then check the listindex, it's -1 instead of the selected value's index:
Code:
Private Sub Form_Load()
With Combo1
.AddItem "1"
.AddItem "2"
.AddItem "3"
.AddItem "4"
End With
Private Sub Combo1_Change() 'fired when typing - not click
'the value's not actually hard-coded
'it selects the index if the typed value matches one of the list entries
'but this simple hard-coding is done for example b/c it doesn't work either
Combo1.ListIndex = 3
End Sub
Private Sub Command1_Click()
MsgBox Combo1.ListIndex 'keeps returning -1
End Sub
Command1 keeps returning -1. If you type a value into the combo, it picks the 2nd item, but outside of that combobox, nothing recognizes this.
Thanks!
-
Aug 4th, 2000, 04:37 PM
#2
Junior Member
try this
Private Sub Form_Load()
With Combo1
.AddItem "1"
.AddItem "2"
.AddItem "3"
.AddItem "4"
End With
End Sub
Private Sub Command1_Click()
MsgBox Combo1.Text 'keeps returning -1
End Sub
HansZ
-
Aug 4th, 2000, 04:43 PM
#3
Thread Starter
Hyperactive Member
But I don't need the text. I need the listindex --- the control is later validated for things like having a valid listindex.
-
Aug 4th, 2000, 10:29 PM
#4
Try:
Code:
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_FINDSTRING = &H14C
Private Sub Form_Load()
Dim lIndex As Long
For lIndex = 1 To 4
Combo1.AddItem lIndex
Next
Combo1 = ""
End Sub
Private Sub Combo1_Validate(Cancel As Boolean)
Dim sText As String
sText = Combo1
Combo1.ListIndex = SendMessage(Combo1.hwnd, CB_FINDSTRING, 0&, ByVal sText)
End Sub
Private Sub Command1_Click()
Caption = Combo1.ListIndex
End Sub
-
Aug 7th, 2000, 09:12 AM
#5
Thread Starter
Hyperactive Member
-
Aug 7th, 2000, 10:30 AM
#6
Thread Starter
Hyperactive Member
Actually what I had works if I put in the validate event -- though yours is more efficient. Is there a way to make this work in the keypress event so that the user doesn't have to tab away to trigger this processing (if a name is found, it populates another control which I'd like to have happen as soon as the user finishes typing a valid name)?
Thanks.
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
|