TListViewFilterEdit
│
English (en) │
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 -
- ListView1.ViewStyle := vsReport;
- ListViewFilterEdit1.FilteredListview := ListView1;
- ListViewFilterEdit1.TextHint := 'Search Here';
- ListViewFilterEdit1.CharCase := ecNormal;
- Possibly create one or more columns in the ListView
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 -
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 -
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 -
if CheckCaseSensitive.checked then
ListViewFilterEdit1.FilterOptions :=
ListViewFilterEdit1.FilterOptions + [fsoCaseSensitive]
else
ListViewFilterEdit1.FilterOptions :=
ListViewFilterEdit1.FilterOptions - [fsoCaseSensitive];
ListViewFilterEdit1.InvalidateFilter;
Other Notes
- You cannot use TListViewFilterEdit with a TListView in Owner Data Mode.
- TListViewFilterEdit will only work with data loaded into the TListViewFilterEdit TListView combination, it cannot be made to look at associated data.
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
- TEdit
- TListView
- provisional documentation on TListViewFilterEdit - external
- Parent Class - official documentation