Jump to content

Listview Filter


JohnBailey
 Share

Recommended Posts

Also, do you have an idea with your version how you'd do a 'begins with'? I've been thinking about it and couldn't come up with something.

On another note, do you think in the version that posted originally that we should answer the question I asked by adding parameters as you did?

A decision is a powerful thing
Link to comment
Share on other sites

  • Replies 48
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Looks rad... could you post an example?

When you do I will direct others in the original post to your simplified version.

Also, do you have an idea with your version how you'd do a 'begins with'? I've been thinking about it and couldn't come up with something.

On another note, do you think in the version that posted originally that we should answer the question I asked by adding parameters as you did?

parameters are in my opinion way easyer and more flexible to work with

Begins with:

hope you understand me here :)

$Len = StringLen($Search_String)
if StringLeft($String_to_looking,$Search_String) Then
    ;stuff
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

parameters are in my opinion way easyer and more flexible to work with

Begins with:

hope you understand me here ;)

nice and ok I'll ask Gesller what he thinks too! :)

Thank you for the feedback and helping to make this better for everyone!! I'm going to work on revamping the "original version." I posted a link in the first post to your simplified version. One note: I recommend posting the data for your "\Data.dat" That way, others can use it immediately as an example.

A decision is a powerful thing
Link to comment
Share on other sites

nice and ok I'll ask Gesller what he thinks too! :)

Thank you for the feedback and helping to make this better for everyone!! I'm going to work on revamping the "original version." I posted a link in the first post to your simplified version. One note: I recommend posting the data for your "\Data.dat" That way, others can use it immediately as an example.

opps, forgot the dat file, its just the one u poste with | insted of the †

Alondra|Kobayashi|09469| 
Daniel|Gagnon|6699|•
Krzysztof|Frost|48296681101|•
Jonas|Wójciknoun|1310781210|•
Simon|Friedman|8764| 
Vytautas|Ang|8810|•
Desmond|Toh|71902748398| 
Rin|Friedman|076|•
Eleanor|Willems|11|•
Athanasios|Wisniewski|006377987110| 
Grace|Gauthier|9443283184| 
John|Hansen|2615113579| 
Dawn|Orpia|10|•
Mariam|Kozlowski|105991| 
Tera||0| 
Athanasios|Smit|887610798| 
Branden|Tal|4392848|•
Samuel|Carter|11100108|•
Jessica|Jensen|30400747544|•
Jacob|Jankowski|106101|•
Tobias|Scott|463| 
Cloe|Kaya|60|•
Shota|Azevedo|410|•
Harris|Grabowski|136895021|•
Zebulun|Walsh|76| 
Krzysztof|Russo|545606|•
Daisy|Klein|428805| 
Khalil||503|•
Tamás|Barros|67| 
|Visser|8262| 
Samuel|Chia||•
Mustafa|Vitols|1010|•
Cloe|Deboina|1031103941027|•
José|Nilsen||•
Thijs|De Vries|1049096437| 
|Jelínek|03903816|•
Daan|Costa|7024| 
Elif|Kaczmarek||•
Yu|Chong|5| 
Mustafa|Barros|9107| 
Tyrone|Kruminš|0101|•
Coraima|Avraham|1834| 
Lukas|Clark|174| 
Archie|Russo|842| 
Veronica||5185021002|•
Felix|Nakamura|745710|•
Petras|Macdonald|7488|•
Delaram|Green|7105971|•
Shota|Yosef|108732121510|•
Arnas|Rizzo|6928645| 
Gabriel|Jansons|878|•
Miguel|Karklinš|1757| 
Lydia|Teo|81020|•
Wilbert|Liepinš|31|•
Faith|Wilson|63198059784|•
Tyra|Adrei|9|•
Ella|Segel|78| 
Lacie|Mitchell|3|•
Zeynep|Zielinski|08209383107| 
Sylvester|Campbell|2128|•
Simon|Müller|461| 
Emily|Dahan|471024101|•
Manuel|Balodis|8962521294|•
Lucas|Amar|41095490660|•
Lucas|Wójciknoun|229953|•
Tadium|Johansen|23|•
Dawson|Vitols|1|•
Daisy|Roy|23| 
Wilbert|Kwiatkowski|17110|•
Thijs|Tay|2810| 
Ethan|Gagnon|386767810|•
Jacob|Barbosa|12835631|•
Vytautas|Gagnon|3| 
Shota|Larsen|0810812| 
Dylan|Shannon|9410| 
Lazaro|Mancini|459| 
Tyreek|Van den Berg|| 
Marc|Sahin|252486978| 
Jordin||813292|•
Shawn|Ong|656509481|•
Krzysztof|O'Sullivan|1075|•
André|Olsen|02828709994| 
Jessica|Low|95|•
Kenta|Low|943510102|•
Mojca|Chia|6|•
Gabriel|Avraham|14121010952| 
Patrick|Chong|6171790| 
Farrukh||5|•
Florian||25227179511| 
William|Martin|611104101066| 
Archie|Wong|0057210403| 
Isidro|Ivanova|6703553|•
Arnas||943| 
Grace|Toh|679382872| 
Tana|Chia|605269107256| 
William|Walsh|45880141012| 
Rose|Piotrowski|109377911066|•
Jordin|Pospíšil|995220|•
Kaito|Gabai|56610570| 
Petunia|Segel|1084961| 
Alanna|Eglitis|3| 
Yu|Koppel|2241022760| 
Aidan|Cardoso|0025542|•
Riko|Flores|100|•
Elif|Visser|503| 
Delaram|Chén|109460771101| 
Gergo|Jankowski|4410| 
Fabian|Cardoso|10108960979|•
Aidan|De Luca|99|•
Celena|Garcia|02|•
Mariam|Nelson|61040410291060| 
Timothy|Li|8940413912|•
Levente||9| 
Yuka|Nowak|398| 
James|Dabrowski|8105416| 
Vytautas|Nilsen|499103566|•
Ren|Schneider|42874991066| 
Ardent|Costa|5|•
Logan|Wozniak|716203760| 
Ardent|Zhou|102| 
Shota|Panther|1509|•
Florian|Finaleas|28|•
|Koppel|87495919310| 
Alijah|Morris|3310| 
Lindsay||10097453| 
|Melo|1210304|•
Fábio|Marino|10|•
Jan|Gomez|0415|•
Athanasios|Baginski|9581010043| 
Diogo|Berzinš|9291| 
Athanasios|Begilins|7262|•
Louis|Wisniewski|658261082294|•
Alanna|Fortin|9026| 
Krystal|Berg||•
Yu|Wong|63781071|•
Joy|Conti|274| 
Delaram|Kristiansen|8596477446| 
Shannon|Janssens|749| 
Takumi|Azevedo|990272710|•
Björn|Martinez|68199107| 
Kaito|Teo|13134|•
Luke|Gagnon|8951029126| 
Sophie|Haugen|2| 
Delbar|De Jong|72215556983|•
Marcin|Andersen|1529| 
Dylan|Zhang|08425276|•
Dawson|Tremblay|836| 
Grace|Katz|100566| 
Máté|Schneider|95391|•
Justin|Malcah|52052|•
Tyler|Koppel|8795103416| 
Aidan|Malcah|10385| 
Logan|Giordano|0| 
Eleanor|Tal|31074091010137|•
Sota|Martin|5839| 
Magnús|Ochion|2294128|•
Carina|Jansons|41047888416| 
Karly|Chen|458108666755|•
Freya|Hall|70|•
Sota|Huáng|510143| 
Lawrence|Teo|791029|•
Coraima|Handel|6| 
Christen|Romano|236|•
|Finaleas|791|•
Lydia|Deboina|19|•
Adam|Lavoie|57701146622|•
Shawn|Halvorsen|10252776|•
Sota|Moshe|0483| 
Lydia|Romano|229|•
Bram|Amar|0133|•
Kaelyn|Martinez|1| 
Konstantinos|Mancini|40616|•
Mojca|Young|8246|•
Shun|Roberts|641073455081| 
Alanna|Ricci|769961| 
Boosah|De Vries|58939174746| 
Fabian|Fernandes|37610773|•
Cassie|Liepinš|789010566337| 
Aidan|Correia|5404|•
Nathan|Claes|4486316| 
Shota|Nakamura|6632643069| 
Ysabela|De Vries|590103| 
Jesse|Chia|10243| 
Alexander|Harris|3998| 
Yuka|Koh|56136897| 
Lavender|Berg|4391010|•
Tyra|Young|010216010539| 
Alexander|Friedman|94106256| 
Axel|Dahan|22658117|•
Jack|Eriksen|29| 
Emily|Peeters|44| 
Mitsuki|Mitchell|1621008764|•
James|Jackson|3|•
Björn|Kelly|7415984| 
Shaina|Paterson|5910936472| 
Violet|Çelik|69480|•
Ádám|De Vries|8465129| 
Farrukh|Chen|81656975021| 
Cloe|Roy|991292| 
Pawel|Nakamura|105602| 
Lazaro|Cunha|466337008|•
Ádám|Bianchi|6103| 
Mitsuki|Luik|65015|•
Manuel|Huáng|74| 
Michail|Rizzo|10372519|•
Zac|Wisniewski|50012257917|•
Patrick|Kozlowski|4151769613|•
Connor|Ramirez|12| 
Lucas|Barbosa|53661| 
Athanasios|Melo|650263170| 
Jan|Baker|57454|•
João|Katz|2| 
Marek|Li|70142966|•
Karly|Jelínek|292| 
Emily|Gagnon|517| 
Coraima|Romano|5381058| 
Jamila|Nilsen|8| 
Carina|Pokorný|0093102510724| 
Gavyn|Chén|30108158|•
|Marino|840536310537|•
Sébastien|Claes|618401831| 
Alondra|Goh|010586895| 
Mara|Schneider|6104268|•
Christen|Smit|910|•
Krystal|Ho|05049623| 
Grace|Ozolinš|457|•
Arnas|Kaminski|31779| 
Faith|Fernandes|1003144041|•
Tadium|Ochion|35| 
Levente|Flores|10024|•
Andre|Ricci|213| 
Alondra|Pelletier|6|•
Ardent|Kowalski|423956810109| 
Deshawn|Halvorsen|819| 
Ioannis|Jacobs|08410|•
Benjamin|Demir|10085205110| 
Magnús|Amar|10910410251710|•
Daiki|Koh|21177512| 
Balázs|Ružicka|36410| 
Sébastien|Barbosa|2910|•
Sienna|Dubois|1|•
Shaina|Klein|96188| 
Harris|Kozlowski|45| 
Archie|Segel|8031092| 
Thijs|O'Sullivan|810608| 
Magnús|Kaczmarek|5491012251040|•
Lachlan|De Jong|84514825210| 
Krzysztof|Kalninš|0022|•
Miu|Giordano|102806| 
Lawrence|Chen|696777| 
Noah|Jansen|41671247410|•
Vayle|Bélanger|394950168| 
Jan|Gonzalez|40610511005|•
Krystal|Král|259| 
Daniel|Ozols|01030855|•
Moe|Kyle|15530|•
Miu|Dahan|27| 
Dimitris|Paterson|26| 
Charlotte|Garcia|1022|•
Lindsay||1010421434|•
Ella|Nguyen|579| 
Shannon|Lambert|934460|
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

Nice filtering :)

Alek:

Here is my version on your simple example (i added more filtering options - so you can choose "on fly" what column will be filtered)...

#Include <GuiListView.au3>
#include <GuiConstants.au3>

Global $Array       = _LV_Create_2DArray(@ScriptDir & "\Data.dat", 'First Name|Last Name|Number|Access')
Global $OldText     = ""
Global $Old_Radio   = ""

GUICreate("", 400, 480, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Listview = GUICtrlCreateListView('First Name|Last Name|Number|Access', 5, 5, 390, 360)
$Input = GUICtrlCreateInput("", 5, 370, 390, 20)

GUICtrlCreateGroup("Filter by...", 5, 400, 390, 70)
$FirstName_Radio = GUICtrlCreateRadio("First Name", 20, 415)
GUICtrlSetState(-1, 1)
$Old_Radio = $FirstName_Radio

$LastName_Radio = GUICtrlCreateRadio("Last Name", 20, 440)
$Number_Radio = GUICtrlCreateRadio("Number", 240, 415)
$Access_Radio = GUICtrlCreateRadio("Access", 240, 440)

For $x = 1 To UBound($Array, 1) - 1
    GUICtrlCreateListViewItem($Array[$x][1] & "|" & $Array[$x][2] & "|" & $Array[$x][3] & "|" & $Array[$x][4], $Listview)
Next

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FirstName_Radio, $LastName_Radio, $Number_Radio, $Access_Radio
            If $Msg <> $Old_Radio And GUICtrlRead($Input) <> "" Then SortByFilterProc()
            $Old_Radio = $Msg
        Case Else
            If GUICtrlRead($Input) <> $OldText Then SortByFilterProc()
    EndSwitch
WEnd

Func SortByFilterProc()
    $OldText = GUICtrlRead($Input)
    
    $IndexFilter = 1
    If GUICtrlRead($LastName_Radio) = 1 Then $IndexFilter = 2
    If GUICtrlRead($Number_Radio) = 1 Then $IndexFilter = 3
    If GUICtrlRead($Access_Radio) = 1 Then $IndexFilter = 4
    
    If $OldText = "" Then
        _LV_Filter($Listview, $Array, 1, -1)
    Else
        _LV_Filter($Listview, $Array, $IndexFilter, $OldText)
    EndIf
EndFunc

Func _LV_Filter($S_LV, $S_LV_Array2D, $LV_Collum_index, $LV_Search_String)
    _GUICtrlListViewDeleteAllItems($S_LV)
    For $x = 1 To UBound($S_LV_Array2D, 1) - 1
        If StringInStr($S_LV_Array2D[$x][$LV_Collum_index], $LV_Search_String) And _
        $LV_Search_String <> "" And $LV_Search_String <> -1 Then
            $Data = ""
            For $y = 1 To UBound($S_LV_Array2D, 2) - 1
                $Data &= $S_LV_Array2D[$x][$y] & "|"
            Next
            GUICtrlCreateListViewItem($Data, $S_LV)
        ElseIf $LV_Search_String = -1 Then
            $Data = ""
            For $y = 1 To UBound($S_LV_Array2D, 2) - 1
                $Data &= $S_LV_Array2D[$x][$y] & "|"
            Next
            GUICtrlCreateListViewItem($Data, $S_LV)
        EndIf
    Next
EndFunc   ;==>_LV_Filter

Func _LV_Create_2DArray($S_File, $S_Header) ;Could use number of headers here and skip the stringsplit
    ;This is the _filecountlines function
    Local $N = FileGetSize($S_File) - 1
    If @error Or $N = -1 Then Return 0
    $Num_Lines = StringLen(StringAddCR(FileRead($S_File, $N))) - $N + 1

    $Num_Header = StringSplit($S_Header, "|")
    Local $LV_Array2D[$Num_Lines + 1][$Num_Header[0] + 1]
    For $x = 1 To $Num_Lines
        $S_Line = FileReadLine($S_File, $x)
        $Data = StringSplit($S_Line, "|")
        For $y = 1 To $Num_Header[0]
            $LV_Array2D[$x][$y] = $Data[$y]
        Next
    Next
    Return $LV_Array2D
EndFunc   ;==>_LV_Create_2DArray

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hi,

If I increase the size of data x8, the 2D array takes 37 secs to start;

I think something using 1D arrays, and RegExp on whole fileRead as String is better and here is a near-working example; [beta 3.2.9.2]

Best, Randall

Edited by randallc
Link to comment
Share on other sites

Hi,

If I increase the size of data x8, the 2D array takes 37 secs to start;

I think something using 1D arrays, and RegExp on whole fileRead as String is better and here is a near-working example; [beta 3.2.9.2]

Best, Randall

looks interesting :)

but lets say i want to add some comboboxs like in JohnBaileys expample, how would that work with your script??

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

Hi,

If I increase the size of data x8, the 2D array takes 37 secs to start;

I think something using 1D arrays, and RegExp on whole fileRead as String is better and here is a near-working example; [beta 3.2.9.2]

Best, Randall

Randall, first i must say WOW!! Wonderful idea! I really disliked the slow start and the problems that Gesller described (#410057 and http://www.autoitscript.com/forum/index.ph...t&p=410081). Thank you VERY MUCH for your input!

Second, I can't get your example to work :) I am missing _GUICtrlListView_GetItemCount () and _GUICtrlListView_DeleteItem ()

I'm going to try just using A3LListview stuff or something in the meantime. Where do I find those two functions?

I have SciTE Version 1.74 and AU3 Production Release 3.2.8.1

A decision is a powerful thing
Link to comment
Share on other sites

looks interesting :)

but lets say i want to add some comboboxs like in JohnBaileys expample, how would that work with your script??

I'm sure this is going to be easy.

EDIT:

I'm working to wrap my limited knowledge around Randall's RegEx usage (which is a fabulous idea), but I'm working on the Combobox stuff right now.

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

Randall,

I used A3LListview.au3

Here's what I adjusted after I included it.

;If _GUICtrlListView_GetItemCount ($S_LV) > UBound($arStringsAft1D) - 1 Then; I didn't have this functions
    If _ListView_GetItemCount($S_LV) > UBound($arStringsAft1D) - 1 Then
        GUISetState(@SW_LOCK)
;For $iIndex = _GUICtrlListView_GetItemCount ($S_LV) - 1 To UBound($arStringsAft1D) Step - 1; I didn't have this functions
        For $iIndex = _ListView_GetItemCount($S_LV) - 1 To UBound($arStringsAft1D) Step - 1
    ;_GUICtrlListView_DeleteItem ($S_LV, $iIndex)
            _ListView_DeleteItem($S_LV, $iIndex)
        Next

And I'm getting this error

lvFilterRegExSet.au3 (83) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: 
GUICtrlSetData($ar_LVhandles[$x], $arStringsAft1D[$x]) 
GUICtrlSetData($ar_LVhandles[$x], ^ ERROR

TO ALL

I just noticed that Randall said he's using the most recent Beta version :">

Edited by JohnBailey
A decision is a powerful thing
Link to comment
Share on other sites

Hi,

If I increase the size of data x8, the 2D array takes 37 secs to start;

I think something using 1D arrays, and RegExp on whole fileRead as String is better and here is a near-working example; [beta 3.2.9.2]

Best, Randall

Is there a way to do this without using Beta 3.2.9.2 and instead just use the most recent Production Release ?

A decision is a powerful thing
Link to comment
Share on other sites

here are some other 1D array based filter.

it is faster then the 2D

sometimes it was unable to get a accurat result when i comperd it with randallcs 1D array filter.

test 1, createing the listviewitems
randallcs Function=978.54
Aleks Function=809.8

test 2, searching, useing copy and paste "Alon"
randallcs Function=2.6
Aleks Function=1.45

The test gui i used.

#Include <GuiListView.au3>
#include <GuiConstants.au3>

Global $LV_Str = FileRead(@ScriptDir & "\Data.dat")
;~ Global $LV_Str = FileRead(@ScriptDir & "\Datasmall.dat")
If @error Then Exit
Global $Array = StringSplit($LV_Str, @LF), $ar_LVhandles[UBound($Array) - 1]
Global $My_Array = _LV_Create_1DArray(@ScriptDir & "\data.dat")
_ArrayDelete($Array,0)
Global $OldText = "", $Old_Radio = ""
GUICreate("", 400, 480, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
$Listview = GUICtrlCreateListView('First Name|Last Name|Number|Access', 5, 5, 390, 360)
$Input = GUICtrlCreateInput("", 5, 370, 390, 20)
GUICtrlCreateGroup("Filter by...", 5, 400, 390, 70)
$FirstName_Radio = GUICtrlCreateRadio("First Name", 20, 415)
GUICtrlSetState(-1, 1)
$Old_Radio = $FirstName_Radio
$LastName_Radio = GUICtrlCreateRadio("Last Name", 20, 440)
$Number_Radio = GUICtrlCreateRadio("Number", 240, 415)
;~ $Access_Radio = GUICtrlCreateRadio("Access", 240, 440)
GUISetState()
Sleep(1000) ; to make sure the gui is properly made
Local $iTimer = TimerInit()
For $x =0 To UBound($Array, 1) - 1
    $ar_LVhandles[$x ] = GUICtrlCreateListViewItem($Array[$x], $Listview)
Next
$iTimer_ArrayRegExpAft1D = Round(TimerDiff($iTimer), 2)
ConsoleWrite("randallcs Function=" & $iTimer_ArrayRegExpAft1D & @LF)

;Randallcs Function got an empty listview then my function should get a empty listview.
_GUICtrlListViewDeleteAllItems($Listview) 

Local $iTimer = TimerInit()
_LV_Filter_1DArray($Listview ,$My_Array ,2, "")
$iTimer_ArrayRegExpAft1D = Round(TimerDiff($iTimer), 2)
ConsoleWrite("Aleks Function=" & $iTimer_ArrayRegExpAft1D & @LF)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $FirstName_Radio, $LastName_Radio, $Number_Radio;, $Access_Radio
            If $Msg <> $Old_Radio And GUICtrlRead($Input) <> "" Then SortByFilterProc()
            $Old_Radio = $Msg
        Case Else
            If GUICtrlRead($Input) <> $OldText Then SortByFilterProc()
    EndSwitch
WEnd

Func SortByFilterProc()
    $OldText = GUICtrlRead($Input)
    $IndexFilter = 1
    If GUICtrlRead($LastName_Radio) = 1 Then $IndexFilter = 2
    If GUICtrlRead($Number_Radio) = 1 Then $IndexFilter = 3
;~  If GUICtrlRead($Access_Radio) = 1 Then $IndexFilter = 4
    If $OldText = "" Then
        _LV_Filter1D($Listview, $LV_Str, 1, -1)
    Else
        ConsoleWrite(@LF)
        
        Local $iTimer = TimerInit();start the timer
        _LV_Filter1D($Listview, $LV_Str, $IndexFilter - 1, $OldText)
        $iTimer_LV_Filter1D = Round(TimerDiff($iTimer) / 1000, 2)
        ConsoleWrite("randallcs Function=" & $iTimer_LV_Filter1D & @LF)
        
        _LV_Filter_1DArray($Listview ,$My_Array ,$IndexFilter, "") ;to refill the listview to make it fair
        
        Local $iTimer = TimerInit() ;Start the timer
        _LV_Filter_1DArray($Listview ,$My_Array ,$IndexFilter, $OldText)
        $iTimer_LV_Filter1D = Round(TimerDiff($iTimer) / 1000, 2)
        ConsoleWrite("Aleks Function=" & $iTimer_LV_Filter1D & @LF)
    EndIf
EndFunc   ;==>SortByFilterProc

Func _LV_Filter1D($S_LV, $S_LV_ReadStr, $LV_Collum_index, $LV_Search_String)
    If $LV_Search_String = -1 Then
        $arStringsAft1D = $Array
    Else
        $arStringsAft1D = _ArrayRegExp($S_LV_ReadStr, $LV_Search_String, $LV_Collum_index, 2, 0);$i_case=2
    EndIf
    If Not IsArray($arStringsAft1D) Then
        Local $arStringsAft1D[1],$c=GUISetState(@SW_LOCK),$c=_GUICtrlListViewDeleteAllItems($S_LV),$c=GUISetState(@SW_UNLOCK)
        ReDim $ar_LVhandles[1 ]
        $ar_LVhandles[0] = GUICtrlCreateListViewItem(" | | | ", $S_LV);($ar_LVhandles[0], $arStringsAft1D[0])
        Return 
    EndIf
    If _GUICtrlListViewGetItemCount ($S_LV) > UBound($arStringsAft1D) - 1 Then
        GUISetState(@SW_LOCK)
        For $iIndex = _GUICtrlListViewGetItemCount ($S_LV) - 1 To UBound($arStringsAft1D) Step - 1
            _GUICtrlListViewDeleteItem ($S_LV, $iIndex)
        Next
        GUISetState(@SW_UNLOCK)
        For $x = 0 To UBound($arStringsAft1D, 1) - 1
            GUICtrlSetData($ar_LVhandles[$x], $arStringsAft1D[$x])
        Next
        ReDim $ar_LVhandles[UBound($arStringsAft1D) ]
    Else
        For $x = 0 To UBound($ar_LVhandles, 1) - 1
            GUICtrlSetData($ar_LVhandles[$x], $arStringsAft1D[$x])
        Next
        ReDim $ar_LVhandles[UBound($arStringsAft1D) ]
        For $y = $x To UBound($arStringsAft1D, 1) - 1
            $ar_LVhandles[$y ] = GUICtrlCreateListViewItem($arStringsAft1D[$y], $S_LV)
        Next
    EndIf
EndFunc   ;==>_LV_Filter1D

Func _ArrayRegExp(Const ByRef $s_FileRead, $s_Searches, $i_Column = 0, $i_Case = 0, $i_NoWildCards = 1)
    Local $s_FirstLine, $i_EndDelim = 1, $i_NoDelim
    If StringInStr($s_FileRead, @LF) Then $s_FirstLine = StringLeft($s_FileRead, StringInStr($s_FileRead, @LF) - 1)
    ConsoleWrite("$s_FirstLine=" & $s_FirstLine & @LF)
    If $i_NoWildCards Then
        $s_Searches = StringReplace(StringReplace($s_Searches, "\", "\\"), ".", "\.");~     $s_Searches = StringReplace(StringReplace($s_Searches, "(", "\("), ")", "\)")
        $s_Searches = StringReplace(StringReplace($s_Searches, "?", "\?"), ".", "*", "\*");~    $s_Searches = StringReplace(StringReplace($s_Searches, "(", "\("), ")", "\)")
    EndIf
    ;=====================================Extra OR needed
    $s_Searches = StringReplace($s_Searches, "|", "+")
    $s_Searches = StringReplace(StringReplace($s_Searches, "+", "|+"), "-", "|^")
    $s_Searches = StringReplace(StringReplace($s_Searches, "=", "|="), " ", "")
    $s_Searches = StringReplace($s_Searches, "&", ".*"); no "or" extra needed
    Local $ar_SearchSplit = StringSplit($s_Searches, "|"), $c = _ArrayDelete($ar_SearchSplit, 0), $arExcludes[1], $ar_SearchSplit2[1], $d = ConsoleWrite("$s_Searches=" & $s_Searches & @LF)
    For $i = 0 To UBound($ar_SearchSplit) - 1
        If $ar_SearchSplit[$i] == "" Then ContinueLoop;_ArrayDelete($ar_SearchSplit, $i)
        If Not StringInStr("+^=&", StringLeft($ar_SearchSplit[$i], 1)) Then _ArrayAdd($ar_SearchSplit2, "[^\|]*" & $ar_SearchSplit[$i] & "[^\|]*")
        If StringLeft($ar_SearchSplit[$i], 1) == "+" Then _ArrayAdd($ar_SearchSplit2, "[^\|]*" & StringTrimLeft($ar_SearchSplit[$i], 1) & "[^\|]*")
        If StringLeft($ar_SearchSplit[$i], 1) == "=" Then _ArrayAdd($ar_SearchSplit2, StringTrimLeft($ar_SearchSplit[$i], 1))
        If StringLeft($ar_SearchSplit[$i], 1) == "^" Then _ArrayAdd($arExcludes, StringTrimLeft($ar_SearchSplit[$i], 1));poost-process extra Excludes in array loop
    Next
    $s_Searches = _ArrayToString($ar_SearchSplit2, "|", 1)
    If Not StringInStr($s_FirstLine, "|") Then $i_NoDelim = 1   ; need to change first part of search string wildcard in 1D array lines ****************
    If StringInStr($s_FirstLine, "|") Then StringReplace($s_FirstLine, "|", "|")
    Local $i_NumCols = @extended, $sStart = '(?:[^\|]*\|)', $sEnd = $sStart, $d = ConsoleWrite("$s_Searches=" & $s_Searches & @LF)
    If $i_Column = $i_NumCols Then $i_EndDelim = 0
    If StringRight($s_Searches, 6) <> "[^\|]*" Then $sEnd = '\|'
    If StringRight($s_Searches, 6) == "[^\|]*" Then $s_Searches = StringTrimRight($s_Searches, 6)
    $s_Searches &= $sEnd & '{' & $i_EndDelim & '}' & ')' & '.*$)' ;$c = ConsoleWrite("$s_Searches=" & $s_Searches & @LF)
    If $i_Case = 2 Or Not $i_Case Then $sStart = '(?i)' & $sStart
    If $i_NoDelim Then $s_Searches = StringReplace($s_Searches, "[^\|]*", ".*")     ; need to change first part of search string wildcard in 1D array lines ***************
    Local $patternReg = '(?m)(^' & $sStart & '{' & $i_Column & '}(?:' & $s_Searches, $c = ConsoleWrite("pattern=" & $patternReg & @LF), $n;
    $ar_Results = StringRegExp($s_FileRead, $patternReg, 3)
    If UBound($arExcludes) > 1 Then
        ConsoleWrite("UBound($arExcludes) =" & UBound($arExcludes) & @LF)
        For $i = 1 To UBound($arExcludes) - 1
            For $j = 0 To UBound($ar_Results) - 1
                Local $patternReg = $sStart & '{' & $i_Column & '}(?:' & "[^\|]*" & $arExcludes[$i] & $sEnd & '{' & $i_EndDelim & '}' & ')' & '.*', $c = ConsoleWrite("pattern=" & $patternReg & @LF);
                If $i_NoDelim Then $patternReg = StringReplace($patternReg, "[^\|]*", ".*"); need to change first part of search string wildcard in 1D array lines
                If StringRegExp($ar_Results[$j], $patternReg, 0) And ($ar_Results[$j] <> "") Then $ar_Results[$j] = ""
            Next
        Next
        Local $s_Result = StringReplace(StringReplace(_ArrayToString($ar_Results, @LF), @LF & @LF, @LF), @LF & @LF, @LF)
        $ar_Results = StringSplit($s_Result, @LF)
        _ArrayDelete($ar_Results, 0)
        If $ar_Results[UBound($ar_Results) - 1] = "" Then _ArrayDelete($ar_Results, UBound($ar_Results) - 1)
    EndIf
    Return $ar_Results
EndFunc   ;==>_ArrayRegExp

Func _LV_Filter_1DArray($LV_Ctrl ,$LV_Array1D ,$LV_Collum_index, $LV_String_to_Search)
    GUISetState(@SW_LOCK)
    _GUICtrlListViewDeleteAllItems($LV_Ctrl)
    For $x = 1 to UBound($LV_Array1D)-1
        $Colum_Text = StringSplit($LV_Array1D[$x],"|")
        If (StringInStr($Colum_Text[$LV_Collum_index],$LV_String_To_Search) Or $LV_String_To_Search = "") Then
            GUICtrlCreateListViewItem($LV_Array1D[$x],$LV_Ctrl)
        EndIf
    Next
    GUISetState(@SW_UNLOCK)
EndFunc

Func _LV_Create_1DArray($P_File)
    Local $N = FileGetSize($P_File) - 1
    If @error Or $N = -1 Then Return 0
    $Num_Lines = StringLen(StringAddCR(FileRead($P_File, $N))) - $N + 1
    
    Local $LV_Array1D[$Num_Lines+1]
    For $x = 1 to $Num_Lines
        $LV_Array1D[$x] = FileReadLine($P_File,$x)
    Next
    Return $LV_Array1D
EndFunc
Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

here are some other 1D array based filter.

it is faster then the 2D

sometimes it was unable to get a accurat result when i comperd it with randallcs 1D array filter.

test 1, createing the listviewitems
randallcs Function=978.54
Aleks Function=809.8

test 2, searching, useing copy and paste "Alon"
randallcs Function=2.6
Aleks Function=1.45
EXCITING!! Great job!

One thing, could you post an example :)

A decision is a powerful thing
Link to comment
Share on other sites

EXCITING!! Great job!

One thing, could you post an example ;)

i did but i needed to edit it and the [ autoit ] tags are a bit wierd when you use quick edit :)

i Edited the 1 you quoted

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

i did but i needed to edit it and the [ autoit ] tags are a bit wierd when you use quick edit :)

i Edited the 1 you quoted

Great! and yeah AutoIt tags are SOOOO weird in this forum (as if there is another forum that uses them ;) ). I've got to go pick some one up and then I'll be back at the office and I'll post the Combobox thing.
A decision is a powerful thing
Link to comment
Share on other sites

randallc's script starts very fast. I get an error on the first letter typed inrto the search..

Line 67

If _GUICrlList_GetItemCount

#412396

or you can just use

If _GUICtrlListViewGetItemCount ($S_LV) > UBound($arStringsAft1D) - 1 Then
        GUISetState(@SW_LOCK)
        For $iIndex = _GUICtrlListViewGetItemCount ($S_LV) - 1 To UBound($arStringsAft1D) Step - 1
            _GUICtrlListViewDeleteItem ($S_LV, $iIndex)
        Next
A decision is a powerful thing
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...