Board index » delphi » Searching a Listview

Searching a Listview

First of all:
I'm a Delphi (4) newbe so i don't know much of it (yet..)

I've got a listview with 3 subitems (so you got 4 collums)

I would like to enter a keyword in an edit _box so that the entries in the
listbox who do not contain that keyword are made invisible

That would be like the way you select newsgroups in Outlook Express

Does anyone knows how this is done?? (if posible)

 

Re:Searching a Listview


RE:

There are many possibilities to achieve this task using iterations among the
list Items:
As you know or will soon find out the ListView, as implies by its name, is a
viewer for memory stored lists, it has a property named "Items", which is a
"TListItems" this object manages a list of "TListItem" objects, which are
the "rows" of data in the ListView, or as I said above the "strings" to be
viewed. each TListItem object has a property of "subItems"' which is a
"TStrings" object, that can contain a list of strings that is defined using
the ListView's concepts as the "columns" of data.
You can scan all the List-Items for any conditions, and delete the ones that
don't meet the condition.

However,
~~~~~~~
This entire concept of using the ListView for such a purpose is incorrect -
you should use a DataSet.
when using a dataset all the logic of iterating data, conditions, tables of
information are all integrated under the DataBase Concepts. for this task
for example I would have chosen a TClientDataSet, creates it in the proper
format (using its TField definitions) applying types (text, number etc) as
needed, and fill with the information that should be viewed. than I would
have used a TDataSource to connect the TClientDataSet to a TDBGrid. all the
information would be visible in this data grid.
AND
even hundreds of records whould be viewed very fast with very little memory
consumption. Y ? - because the TDBGrid component retrieves information for
one page only - each time you pages up or down it gets more and more
information as needed. so, Y the ListView dont act the same ? - simply, its
designed for a different task - View small (relatively) static data
structures - it holds all its info in memory - it doesnt use the Database
concepts of smart huge data management like implemented in the DataSets
components.
PLUS
all conditions can be represented as simple SQL queries - remember its a
database-like engine beneath.

Notes:
* For a fast Flittering reaction you can use the Filtering mechanism
supported by the DataSet, its real effective for couple of hundred records,
if you got more don't use it - use SQL instead.
* You can actually use any type of DataSet, TClientDataSet, is only an
example, if you have MANY records use the TQuery with a real DB.

(-:

Michael M.

Quote
Erik Versaevel wrote in message ...
>First of all:
>I'm a Delphi (4) newbe so i don't know much of it (yet..)

>I've got a listview with 3 subitems (so you got 4 collums)

>I would like to enter a keyword in an edit _box so that the entries in the
>listbox who do not contain that keyword are made invisible

>That would be like the way you select newsgroups in Outlook Express

>Does anyone knows how this is done?? (if posible)

Other Threads