Sign in Join
Wiki copytemporary

TListViewFilterEdit: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<figure>
2-<img src="ListViewFilterEdit.png" title="ListViewFilterEdit.png" />
3-<figcaption>ListViewFilterEdit.png</figcaption>
4-</figure>
1+![](/wiki-images/4/4c/ListViewFilterEdit.png)
52
63A **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]].
74
85## Usage
96
107Normally you would place a TListViewFilterEdit near its associated TListView and set a number of properties of the two components, typically -
118
129- ListView1.ViewStyle := vsReport;
1310- ListViewFilterEdit1.FilteredListview := ListView1;
1411- ListViewFilterEdit1.TextHint := 'Search Here';
1512- ListViewFilterEdit1.CharCase := ecNormal;
1613- Possibly create one or more columns in the ListView
1714
1815### Adding Data
1916
2017Data 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 -
2118
2219``` pascal
2320procedure TForm1.AddLVItem(St1, St2 : string);
2421var
2522 ListItem: TListViewDataItem;
2623begin
2724 ListItem.Data := Nil;
2825 SetLength(ListItem.StringArray, 2);
2926 ListItem.StringArray[0] := St1;
3027 ListItem.StringArray[1] := St2;
3128 ListViewFilterEdit1.Items.Add(ListItem);
3229end;
3330
3431procedure TForm1.LoadSomeData();
3532begin
3633 ListView1.BeginUpdate;
3734 AddLVItem('String1', 'String2');
3835 AddLVItem('String3', 'String4');
3936 AddLVItem('A String', 'another String');
4037 AddLVItem('x string', 'Extra String');
4138 ListViewFilterEdit1.InvalidateFilter;
4239 ListViewFilterEdit1.ResetFilter;
4340 ListViewFilterEdit1.Text:='';
4441 ListView1.EndUpdate;
4542end;
4643```
4744
4845### Filter Data
4946
5047By 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 -
5148
5249``` pascal
5350 ListViewFilterEdit1.ByAllFields := CheckBothColumns.Checked;
5451 ListViewFilterEdit1.InvalidateFilter;
5552```
5653
5754### Case Sensitive
5855
5956Again, by default, TListViewFilterEdit is not case sensitive but can easily be made so. Again, suppose we have a checkbox, this time called CheckCaseSensitive -
6057
6158``` pascal
6259 if CheckCaseSensitive.checked then
6360 ListViewFilterEdit1.FilterOptions :=
6461 ListViewFilterEdit1.FilterOptions + [fsoCaseSensitive]
6562 else
6663 ListViewFilterEdit1.FilterOptions :=
6764 ListViewFilterEdit1.FilterOptions - [fsoCaseSensitive];
6865 ListViewFilterEdit1.InvalidateFilter;
6966```
7067
7168### Other Notes
7269
7370- You cannot use TListViewFilterEdit with a TListView in Owner Data Mode.
7471- TListViewFilterEdit will only work with data loaded into the TListViewFilterEdit TListView combination, it cannot be made to look at associated data.
7572
7673The above code can be found in a Lazarus Example that may, at some point in time find its way into the Lazarus Source tree.
7774
7875## See Also
7976
8077- [[TEdit]]
8178- [[TListView]]
8279- [provisional documentation on TListViewFilterEdit](https://dsiders.gitlab.io/lazdocsnext/lazcontrols/listviewfilteredit/tlistviewfilteredit.html) - external
8380- [Parent Class](https://lazarus-ccr.sourceforge.io/docs/lcl/editbtn/tcustomcontrolfilteredit.html) - official documentation
8481
8582---
8683*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](/wiki-contact).*

Back to history