|
-
Dec 13th, 2004, 06:23 PM
#1
Thread Starter
Frenzied Member
[RESOLVED]Combo and SQL
Hi:
I have a combo with a few items like:
"Superman"
"Spiderman"
"catwoman"
"BAtman"
and I want,when I enter in the box,the letter "b",the combo shows the name batman for example....this is possible to do in VB?
If yes ,can anybody put a few lines off code to do this?
Thanks
Last edited by sacramento; Dec 14th, 2004 at 07:30 AM.
-
Dec 13th, 2004, 06:30 PM
#2
Re: Combo and SQL
that is the default action of the combobox. doesn't it work?
-
Dec 13th, 2004, 06:37 PM
#3
Thread Starter
Frenzied Member
Re: Combo and SQL
Hi:
sorry I don't now what you want mean about:
"that is the default action of the combobox"
Can you see a more expecific,please?
Thanks
-
Dec 13th, 2004, 06:39 PM
#4
Re: Combo and SQL
after you load it, if you click in the combobox, and type a letter, then the first item that starts with that letter is brought to the top, and selected.
-
Dec 13th, 2004, 06:48 PM
#5
New Member
Re: Combo and SQL
no the default behaviour is not that, thats why i guess there are so many combox control for sale on the web.
I just made that piece of code for you, it's not perfect but i'm sure you can improve it to suit your needs.
Create a new form with a combobox, and paste that stuff in the code :
Code:
Option Explicit
Private Sub Combo1_Change()
Dim l_strLenght As Long
Dim i As Long
l_strLenght = Len(Combo1.Text)
If l_strLenght = 0 Then Exit Sub
For i = 0 To Combo1.ListCount - 1
If StrComp(Combo1.Text, Left(Combo1.List(i), l_strLenght), vbTextCompare) = 0 Then
Exit For
End If
Next i
If i < Combo1.ListCount Then
Combo1.ListIndex = i
Combo1.SelStart = l_strLenght
Combo1.SelLength = Len(Combo1.Text) - l_strLenght
End If
End Sub
Private Sub Form_Load()
Combo1.AddItem "Allo"
Combo1.AddItem "Bllo"
Combo1.AddItem "Cllo"
Combo1.AddItem "Dllo"
Combo1.ListIndex = 0
End Sub
What does it do ?
Each time you modify the text of the combo it check the list to see if something starting like that exist, if yes, it select it. I also made it so it select the remaining of the text so you can keep typing.
In your example if you type s, it would select spiderman, with "piderman" selected, so if you type a "u" after the "s" it'll select superman.
Hard to explain, but easy to see, just try it.
PS: i made that in 5 mins, dont shout at me if there are bugs in it
-
Dec 13th, 2004, 06:53 PM
#6
Re: Combo and SQL
I put 0,8, ... 808 into a combo, and when I press 8, it get the cell for 8, if i press it again, i get 808, etc. if I type 80, it goes right to 808.
It is a dropdown list. btw - selected item works right. I don't know whats wrong with mine. it's behaving oddly.
Last edited by dglienna; Dec 13th, 2004 at 07:00 PM.
-
Dec 13th, 2004, 06:57 PM
#7
New Member
Re: Combo and SQL
what ?
-
Dec 13th, 2004, 07:01 PM
#8
Re: Combo and SQL
i used a new project, and made a combo, and loaded it with his data.
when I set the style to 2 and ran it, it jumpled automatically.
-
Dec 13th, 2004, 07:07 PM
#9
New Member
Re: Combo and SQL
It's just meant to be used with style = 0, that's just an example to get the poster started, not a full dumb proof solution.
It can still be improved, example in my code you might wanna check if the last key pressed is the backspace, or you might see weird things
-
Dec 13th, 2004, 08:12 PM
#10
Re: Combo and SQL
sorry, i was getting upset about why my combo wasn't working the way that it should. i knew that it was jumping to the right item with a keypress, though. there are 3 styles of combo, and they each act differently.
-
Dec 14th, 2004, 03:18 AM
#11
Fanatic Member
Re: Combo and SQL
maybe u wanna try combobox from Microsoft Form 2.0 Object Library and set it style property to frmStyledropDownList..
it acts like the one u want
regards
-
Dec 14th, 2004, 07:31 AM
#12
Thread Starter
Frenzied Member
Re: [RESOLVED]Combo and SQL
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
|