CAsba,
In general I avoid loops where possible because they can be processor intensive.
From what I can tell, you have broadly 2 choices:
Option 1
Filter the datagrid so it only shows the found lines. Use the
Filter method I posted above and set the dgData of the datagrid to the resulting array.
To not lose your data ensure the full data set is stored somewhere - typically I'll store this in a custom property of the datagrid, ie after populating the first time, I:
Code: Select all
set the uAllData of <myGrid> to the dgData of <myGrid>
This creates a custom property
uAllData of the datagrid that contains the full data set. When filtering I use the above method to get the found elements of the array and set the dgData of the datagrid to this:
Code: Select all
set the dgData of group <myGrid> to tArray
Since you have record of all data - to restore this, simply
Code: Select all
set the dgData of <myGrid> to the uAllData of <myGrid>
Option 2
You don't filter the datagrid - instead use the
Filter method above to get the found indexes. In the resulting array, the data is keyed by the source array element's index. In my example:
tKeys will now contain a return-delimited list of all indexes found - this is not the same as line number.
You can either just set
the dgHilitedIndexes of the datagrid to
tKeys (keeping in mind you have to change the return delimited list to a comma delimited list), or if you want the line numbers, convert the indexes to line numbers with
dgLineOfIndex and then set
the dgHilitedLines instead.
Then you would need to scroll down to the found line(s) - use the datagrid's property
dgVScroll. But I'll leave that as an exercise to you if you want to do this.
Personally I always go with option 1, much simpler.
Typically I'll have a field acting as a filter and use it's
on textChanged handler to run the filter command that includes the above, but equally if the filter field is empty I simply restore the full data set with uAllData. But that's just my preference...