|
-
Nov 22nd, 1999, 09:59 PM
#1
Thread Starter
Addicted Member
I am looking to do an incremental search in a listview. I know it is possible to do it with an API and a listbox but I really would like to use a listview.
Is it possible and how ?
-
Nov 22nd, 1999, 10:10 PM
#2
What do you mean by Incremental search?
------------------
Serge
Software Developer
[email protected]
[email protected]
ICQ#: 51055819
[This message has been edited by Serge (edited 11-23-1999).]
-
Nov 22nd, 1999, 10:29 PM
#3
Thread Starter
Addicted Member
I mean that as you type in a text box, the list selects the nearest match...
(sorry I should have been more specific)
-
Nov 22nd, 1999, 10:35 PM
#4
Try this:
Code:
Private Type LV_FINDINFO
flags As Long
psz As String
lParam As Long
pt As Long
vkDirection As Long
End Type
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 LVFI_STRING = &H2
Private Const LVFI_PARTIAL = &H8
Private Const LVM_FINDITEM = LVM_FIRST + 13
Private Sub ListView1_KeyPress(KeyAscii As Integer)
Static sWord As String
Dim iIndex As Long
Dim tLVFI As LV_FINDINFO
sWord = sWord & Chr(KeyAscii)
tLVFI.flags = LVFI_PARTIAL Or LVFI_STRING
tLVFI.psz = sWord
iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
If iIndex < 0 Then
sWord = Chr(KeyAscii)
tLVFI.psz = sWord
iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
End If
If iIndex < 0 Then
sWord = ""
Else
Set ListView1.SelectedItem = ListView1.ListItems(iIndex + 1)
End If
KeyAscii = 0
End Sub
This acceptes Typing directly into the Listview, just move the Code to a Textbox if you want to do it from there.
This code example I've put together assumes the Listview is Sorted.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
[This message has been edited by Aaron Young (edited 11-23-1999).]
-
Nov 23rd, 1999, 04:00 AM
#5
Thread Starter
Addicted Member
Thank you Aaron...
There is one constant that is not declared in your code and (hehehe) I REALLY don't know what to do with it...
at the line: Public Const LVM_FINDITEM = LVM_FIRST + 13
VB tells me that LVM_FIRST is not declared...
-
Nov 23rd, 1999, 04:07 AM
#6
Sorry about that, I have no Idea how I missed it, anyway, here's the Constant:
Private Const LVM_FIRST = &H1000
Just add it in above LVM_FINDITEM
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 23rd, 1999, 04:09 AM
#7
Thread Starter
Addicted Member
Cool thanks a lot
-
Nov 23rd, 1999, 04:36 AM
#8
Thread Starter
Addicted Member
Still i little problem .... I have put your code in the keypress event of my textbox and when I type in it, nothing happens...
Any ideas??
-
Nov 23rd, 1999, 04:42 AM
#9
Make sure the ListViews HideSelection Property is False, then use this slightly Modified version of my code:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Static sWord As String
Dim iIndex As Long
Dim tLVFI As LV_FINDINFO
Dim iPos As Integer
sWord = sWord & Chr(KeyAscii)
tLVFI.flags = LVFI_PARTIAL Or LVFI_STRING
tLVFI.psz = sWord
iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
If iIndex < 0 Then
sWord = Chr(KeyAscii)
tLVFI.psz = sWord
iIndex = SendMessage(ListView1.hwnd, LVM_FINDITEM, -1, tLVFI)
End If
If iIndex < 0 Then
sWord = ""
Else
Set ListView1.SelectedItem = ListView1.ListItems(iIndex + 1)
End If
iPos = Text1.SelStart
Text1 = sWord
Text1.SelStart = iPos + 1
KeyAscii = 0
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 23rd, 1999, 09:50 AM
#10
Thread Starter
Addicted Member
Ok the code works fine but my list has more items than can be shown... and as it searches, the focus goes out of sight... (the list doesn't "slide" to the selected item) is there a way to do it?
And also the selection is in grey, is there a way to make it blue (as usual)?
Thanks for your help Aaron!
-
Nov 23rd, 1999, 10:02 AM
#11
This post goes on much longer, we'll have to start discussing my consultation fees.. 
To make sure the Item Highlighted can be seen, add this line after Set ListVew1.SelectedItem = ..
ListView1.SelectedItem.EnsureVisible
The only way you're going to be able to change the Highlight color is to Subclass the Control and Draw the Control yourself.
Not really worth the hassle for the sake of just changing the Color.
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
-
Nov 23rd, 1999, 11:28 AM
#12
Thread Starter
Addicted Member
You know what? I found this little method called FINDITEM which does the same thing as your code does...
I have this line on the keyup of my textbox:
lstRecherche.SelectedItem = lstRecherche.FindItem(txtRechercher, lvwText, , lvwPartial)
and it does the trick (sorry for the hassle )
as for the MakeSureVisible thing.... didn't know that and will try it right now! Thanks again ( A LOT ! )
You're the best!
p.s.: just to know... How long have you been programming ? (any language)
-
Dec 3rd, 1999, 09:20 PM
#13
New Member
Hi,
I am writing a program so when you write text in a text box it displays the same text in a label but backwards eg.
text box = Jason
label = nosaJ
Can someone please help me???
Thanks in advance.
-
Dec 3rd, 1999, 09:35 PM
#14
-
Dec 3rd, 1999, 09:54 PM
#15
Hyperactive Member
If you have VB6, then you can use the StrReverse function like this:
Code:
Private Sub Command1_Click()
Text1.Text = StrReverse(Text1.Text)
End Sub
Remember, that only works with VB6.
------------------
Tom Young, 14 Year Old
[email protected]
ICQ: 15743470 Add Me ICQ Me
AIM: TomY10
PERL, JavaScript and VB Programmer
-
Dec 4th, 1999, 06:33 AM
#16
-
Dec 5th, 1999, 12:52 PM
#17
Member
If you don't have VB6, add two labels on your form
Code:
Private Sub Form_Load()
Dim sstring As String
Dim iposition As Integer
Label1.Caption = "VB PROGRAMMER"
sstring = Label1.Caption
For iposition = Len(sstring) To 1 Step -1
Label2.Caption = Label2.Caption & Mid$(sstring, iposition, 1)
Next
End Sub
Hope this works for you
Ruchi
-
Dec 6th, 1999, 01:03 PM
#18
Addicted Member
Just try formatting your string on the text click event, (in vb5) automatically reverses it.
txtEntry.Click()
txtEntry = UCASE(txtEntry)
Just add whatever code you want to use for this weird happening, e.g label = UCASE(txtEntry)
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
|