Skip to content

Commit 70d07fc

Browse files
authored
Update README.md
1 parent a1b4ce9 commit 70d07fc

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

README.md

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
11
# How to Filter the Dropdown Items in WinForms SfComboBox
2-
This repository demonstrates how to filter items in the Syncfusion WinForms SfComboBox control using the built-in filtering feature. The SfComboBox is a modern replacement for the standard ComboBox, offering advanced features such as data binding, auto-complete, and customizable filtering logic. Filtering allows you to display only relevant items based on user-defined conditions, improving usability and performance in applications with large datasets.
2+
This repository demonstrates how to filter items in the Syncfusion WinForms **SfComboBox** control using its built-in filtering feature. The SfComboBox is a modern replacement for the standard ComboBox, offering advanced features such as **data binding**, **auto-complete**, and **customizable filtering** logic. Filtering allows you to display only relevant items based on user-defined conditions, improving usability and performance in applications with large datasets.
33

44
## Key Features Demonstrated in This Sample
5-
Apply custom filtering logic using the Filter property of DropDownListView.
6-
Refresh the filter dynamically at runtime.
7-
Use predicates to determine which items should be visible in the dropdown.
5+
- Apply custom filtering logic using the Filter property of DropDownListView.
6+
- Refresh the filter dynamically at runtime.
7+
- Use predicates to determine which items should be visible in the dropdown.
88

99
## How Filtering Works
10-
The Filter property accepts a predicate that is evaluated for each item in the data source. If the predicate returns true, the item remains visible; otherwise, it is hidden. This approach provides flexibility to implement complex filtering scenarios such as prefix matching, substring search, or conditional visibility based on multiple fields.
10+
The _Filter_ property accepts a **predicate** that is evaluated for each item in the data source.
11+
- If the predicate returns _true_, the item remains visible.
12+
- If it returns _false_, the item is hidden.
13+
14+
This approach provides flexibility to implement complex filtering scenarios such as:
15+
- Prefix matching
16+
- Substring search
17+
- Conditional visibility based on multiple fields
1118

1219
## Example Code (C#)
13-
```csharp
20+
```C#
1421
public Form1()
1522
{
16-
InitializeComponent();
23+
InitializeComponent();
1724

18-
List<USState> list = GetData();
19-
this.sfComboBox1.DataSource = list;
20-
this.sfComboBox1.DisplayMember = "LongName";
21-
this.sfComboBox1.ThemeName = "Office2016Colorful";
22-
this.sfComboBox1.DropDownListView.Style.ItemStyle.Font = new Font("Microsoft Sans Serif", 9.75f);
25+
List<USState> list = GetData();
26+
this.sfComboBox1.DataSource = list;
27+
this.sfComboBox1.DisplayMember = "LongName";
28+
this.sfComboBox1.ThemeName = "Office2016Colorful";
29+
this.sfComboBox1.DropDownListView.Style.ItemStyle.Font = new Font("Microsoft Sans Serif", 9.75f);
2330

24-
// Apply filter
25-
sfComboBox1.DropDownListView.View.Filter = FilterItem;
26-
sfComboBox1.DropDownListView.View.RefreshFilter();
31+
// Apply filter
32+
sfComboBox1.DropDownListView.View.Filter = FilterItem;
33+
sfComboBox1.DropDownListView.View.RefreshFilter();
2734
}
2835

2936
// Filter predicate
3037
private bool FilterItem(object data)
3138
{
32-
if ((data as USState).LongName.StartsWith("C"))
33-
return true;
34-
return false;
39+
return (data as USState).LongName.StartsWith("C");
3540
}
3641
```
42+
This sample filters the dropdown items so that only states starting with the letter "C" are displayed. You can modify the predicate to implement custom logic such as filtering by length, region, or any other property.
3743

38-
This sample filters the dropdown items so that only states starting with the letter C are displayed. You can modify the predicate to implement custom logic such as filtering by length, region, or any other property.
39-
40-
For more details, refer to the official UG documentation:
41-
🔗 [Filtering in Windows Forms SfComboBox](https://help.syncfusion.com/windowsforms/combobox/filtering)
44+
## Reference
45+
For more details, refer to the official UG documentation: [Filtering in Windows Forms SfComboBox](https://help.syncfusion.com/windowsforms/combobox/filtering)

0 commit comments

Comments
 (0)