Sign in Join
Wiki copytemporary

TListViewFilterEdit

A TListViewFilterEdit is a control, based on TEdit that can manage filtering of the content of a TListView component. It is available from the LazControls tab of the Component Palette.

Usage

Normally you would place a TListViewFilterEdit near its associated TListView and set a number of properties of the two components, typically -

Adding Data

Data is added via the TListViewFilterEdit and it takes care of passing that data to the TListView. For example, to populate two columns of the TListView you might -

pascal
procedure TForm1.AddLVItem(St1, St2 : string);
var
    ListItem: TListViewDataItem;
begin
    ListItem.Data := Nil;
    SetLength(ListItem.StringArray, 2);
    ListItem.StringArray[0] := St1;
    ListItem.StringArray[1] := St2;
    ListViewFilterEdit1.Items.Add(ListItem);
end;

procedure TForm1.LoadSomeData();
begin
    ListView1.BeginUpdate;
    AddLVItem('String1',  'String2');
    AddLVItem('String3',  'String4');
    AddLVItem('A String', 'another String');
    AddLVItem('x string', 'Extra String');
    ListViewFilterEdit1.InvalidateFilter;
    ListViewFilterEdit1.ResetFilter;
    ListViewFilterEdit1.Text:='';
    ListView1.EndUpdate;
end;

Filter Data

By default, TListViewFilterEdit filters only on data in the first column. You can tell it to look at all columns, suppose you have a checkbox called CheckBothColumns -

pascal
    ListViewFilterEdit1.ByAllFields := CheckBothColumns.Checked;
    ListViewFilterEdit1.InvalidateFilter;

Case Sensitive

Again, by default, TListViewFilterEdit is not case sensitive but can easily be made so. Again, suppose we have a checkbox, this time called CheckCaseSensitive -

pascal
    if  CheckCaseSensitive.checked then
       ListViewFilterEdit1.FilterOptions :=
            ListViewFilterEdit1.FilterOptions + [fsoCaseSensitive]
    else
       ListViewFilterEdit1.FilterOptions :=
            ListViewFilterEdit1.FilterOptions - [fsoCaseSensitive];
    ListViewFilterEdit1.InvalidateFilter;

Other Notes

The above code can be found in a Lazarus Example that may, at some point in time find its way into the Lazarus Source tree.

See Also


From the Free Pascal wiki, page "TListViewFilterEdit", as it stood on 2022-12-07 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.