-
August 29th, 2012, 12:46 PM
#1
sort a field in listview items by letter by letter entered in textbox txtsearch
Hai Every one I am new to this forum
I wrote code to sort listview items letter by letter ie., a,b,s like that (indexing the column)
The code I wrote is :
Code:
Private Sub txtsearch_Change()
ListView1.ListItems.Clear
Dim list As ListItem
Dim x As Integer
connectDB
rs.Open "Select*from accreg where Title line'"&txtsearch&"%'", db, 3, 3
Do Until rs.EOF
Set list = ListView1.ListItems.add(, , rs(0))
For x = 1 To 3 'number of fields in the date base minus one
list.SubItems(x) = rs(x)
Next x
rs.MoveNext
Loop
Set rs = Nothing
db.Close: Set db = Nothing
End Sub
But the error is Compile error
syntax error the following line of code coloured in Red.
Code:
rs.Open "Select*from accreg where Title line'"&txtsearch&"%'", db, 3, 3
kindly see the code above and give your valuable suggestion.http://www.youtube.com/results?searc...+Part+6&page=4 i need the result of code in video i.e, search fullname
-
August 31st, 2012, 11:11 AM
#2
Re: sort a field in listview items by letter by letter entered in textbox txtsearch
Change to
Code:
rs.Open "Select * from accreg where Title like '" & txtsearch.text & "%'", db, 3, 3
I'm not quite sure, but I think there are some spaces required, at least between "like" and the searchtext, also after Select, I think.
Try this line and tell us if it works any better.
-
August 31st, 2012, 11:34 AM
#3
Re: sort a field in listview items by letter by letter entered in textbox txtsearch
Mr.WoF Sir,
I am (very)n (n is positive integer) Thankful to you for your reply which is perfectly working. I am working on this bit of code ie., txtsearch_change from last 15 days.
Thanks once again
I wish to proceed further in my project until then may leave this thread intact or should be closed, if necessary to close, let me know how to close a thread.
-
August 31st, 2012, 11:52 PM
#4
Re: sort a field in listview items by letter by letter entered in textbox txtsearch
Thread Tools, at the TOP of this post...
-
September 6th, 2012, 07:41 AM
#5
Re: sort a field in listview items by letter by letter entered in textbox txtsearch
To do this you need win32 api, it's not hard, not easy:
Your sort function contains something like this (sample is for date sorting, but you can change it for other datatypes):
On sort:
SendMessage Listview.hWnd, LVM_SORTITEMS, Listview.hWnd, ByVal lp2val(AddressOf ListviewCompareDate)
Function ListviewCompareDate&(ByVal lParam1&, ByVal lParam2&, ByVal hWnd&)
'Param1 and Param2 are the values to compare
'mbSorted contains the sort state of the Listview
Dim d1 As Date, d2 As Date
d1 = ListviewItemDate(hWnd, lParam1)
d2 = ListviewItemDate(hWnd, lParam2)
If d1 = d2 Then
ListviewCompareDate= 1
Else
ListviewCompareDate= IIf(mbSorted Xor d1 > d2, 0, 2)
End If
End End
Private Function ListviewItemDate(hWnd&, lParam&) As Date
Dim hX&, uFI As LV_FINDINFO, uLi As LV_ITEM, l&
uFI.flags = LVIF_TEXT
uFI.lParam = lParam
hX = SendMessage(hWnd, LVM_FINDITEM, -1, uFI)
With uLi
.mask = LVIF_TEXT
.iSubItem = miSortKey
.pszText = Space$(32)
.cchTextMax = Len(.pszText)
l = SendMessage(hWnd, LVM_GETITEMTEXT, hX, uLi)
If l Then ListviewItemDate = CDate(Left$(.pszText, l))
End With
End Function
You can create your own function to change datacompare for Integers, strings or whatever you like.
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
|