PDA

Click to See Complete Forum and Search --> : Reversing text in a text box????????


David Laplante
Nov 22nd, 1999, 08:59 PM
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 ?

Serge
Nov 22nd, 1999, 09:10 PM
What do you mean by Incremental search?

------------------

Serge

Software Developer
Serge_Dymkov@vertexinc.com
Access8484@aol.com
ICQ#: 51055819 (http://www.icq.com/51055819)



[This message has been edited by Serge (edited 11-23-1999).]

David Laplante
Nov 22nd, 1999, 09:29 PM
I mean that as you type in a text box, the list selects the nearest match...

(sorry I should have been more specific)

Aaron Young
Nov 22nd, 1999, 09:35 PM
Try this:

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
aarony@redwingsoftware.com
adyoung@win.bright.net


[This message has been edited by Aaron Young (edited 11-23-1999).]

David Laplante
Nov 23rd, 1999, 03:00 AM
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...

Aaron Young
Nov 23rd, 1999, 03:07 AM
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
aarony@redwingsoftware.com
adyoung@win.bright.net

David Laplante
Nov 23rd, 1999, 03:09 AM
Cool thanks a lot :)

David Laplante
Nov 23rd, 1999, 03:36 AM
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??

Aaron Young
Nov 23rd, 1999, 03:42 AM
Make sure the ListViews HideSelection Property is False, then use this slightly Modified version of my 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
aarony@redwingsoftware.com
adyoung@win.bright.net

David Laplante
Nov 23rd, 1999, 08:50 AM
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!

Aaron Young
Nov 23rd, 1999, 09:02 AM
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
aarony@redwingsoftware.com
adyoung@win.bright.net

David Laplante
Nov 23rd, 1999, 10:28 AM
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)

biosupgrade
Dec 3rd, 1999, 08:20 PM
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.

Steve Stunning
Dec 3rd, 1999, 08:35 PM
Thry this, it works.. :)

Word = Text1.Text
L = Len(Word)
Temp = String$(L, 32)

For x = 1 To L
a = Mid$(Word, x, 1)
Mid$(Temp, (L - x) + 1, 1) = a
Next x

Label1.Caption = Temp

Compwiz
Dec 3rd, 1999, 08:54 PM
If you have VB6, then you can use the StrReverse function like this:


Private Sub Command1_Click()
Text1.Text = StrReverse(Text1.Text)
End Sub


Remember, that only works with VB6.

------------------
Tom Young, 14 Year Old
tyoung@stny.rr.com
ICQ: 15743470 (http://wwp.icq.com/15743470) Add Me (http://wwp.icq.com/scripts/search.dll?to=15743470) ICQ Me (http://wwp.icq.com/scripts/contact.dll?msgto=15743470)
AIM: TomY10 (http://www.aol.com/aim/aim30.html)
PERL, JavaScript and VB Programmer

Steve Stunning
Dec 4th, 1999, 05:33 AM
I did not know that... :) Learn somthing new here every day!!!

Ruchi
Dec 5th, 1999, 11:52 AM
If you don't have VB6, add two labels on your form


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

jritchie
Dec 6th, 1999, 12:03 PM
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)