Sign in Join
Wiki copytemporary

TListViewFilterEdit: what changed

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

Title: TListViewFilterEdit

OldNewLine
1+<figure>
2+<img src="ListViewFilterEdit.png" title="ListViewFilterEdit.png" />
3+<figcaption>ListViewFilterEdit.png</figcaption>
4+</figure>
5+
6+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]].
7+
8+## Usage
9+
10+Normally you would place a TListViewFilterEdit near its associated TListView and set a number of properties of the two components, typically -
11+
12+- ListView1.ViewStyle := vsReport;
13+- ListViewFilterEdit1.FilteredListview := ListView1;
14+- ListViewFilterEdit1.TextHint := 'Search Here';
15+- ListViewFilterEdit1.CharCase := ecNormal;
16+- Possibly create one or more columns in the ListView
17+
18+### Adding Data
19+
20+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 -
21+
22+``` pascal
23+procedure TForm1.AddLVItem(St1, St2 : string);
24+var
25+ ListItem: TListViewDataItem;
26+begin
27+ ListItem.Data := Nil;
28+ SetLength(ListItem.StringArray, 2);
29+ ListItem.StringArray[0] := St1;
30+ ListItem.StringArray[1] := St2;
31+ ListViewFilterEdit1.Items.Add(ListItem);
32+end;
33+
34+procedure TForm1.LoadSomeData();
35+begin
36+ ListView1.BeginUpdate;
37+ AddLVItem('String1', 'String2');
38+ AddLVItem('String3', 'String4');
39+ AddLVItem('A String', 'another String');
40+ AddLVItem('x string', 'Extra String');
41+ ListViewFilterEdit1.InvalidateFilter;
42+ ListViewFilterEdit1.ResetFilter;
43+ ListViewFilterEdit1.Text:='';
44+ ListView1.EndUpdate;
45+end;
46+```
47+
48+### Filter Data
49+
50+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 -
51+
52+``` pascal
53+ ListViewFilterEdit1.ByAllFields := CheckBothColumns.Checked;
54+ ListViewFilterEdit1.InvalidateFilter;
55+```
56+
57+### Case Sensitive
58+
59+Again, by default, TListViewFilterEdit is not case sensitive but can easily be made so. Again, suppose we have a checkbox, this time called CheckCaseSensitive -
60+
61+``` pascal
62+ if CheckCaseSensitive.checked then
63+ ListViewFilterEdit1.FilterOptions :=
64+ ListViewFilterEdit1.FilterOptions + [fsoCaseSensitive]
65+ else
66+ ListViewFilterEdit1.FilterOptions :=
67+ ListViewFilterEdit1.FilterOptions - [fsoCaseSensitive];
68+ ListViewFilterEdit1.InvalidateFilter;
69+```
70+
71+### Other Notes
72+
73+- You cannot use TListViewFilterEdit with a TListView in Owner Data Mode.
74+- TListViewFilterEdit will only work with data loaded into the TListViewFilterEdit TListView combination, it cannot be made to look at associated data.
75+
76+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.
77+
78+## See Also
79+
80+- [[TEdit]]
81+- [[TListView]]
82+- [provisional documentation on TListViewFilterEdit](https://dsiders.gitlab.io/lazdocsnext/lazcontrols/listviewfilteredit/tlistviewfilteredit.html) - external
83+- [Parent Class](https://lazarus-ccr.sourceforge.io/docs/lcl/editbtn/tcustomcontrolfilteredit.html) - official documentation
84+
85+---
86+*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