How to implement custom filtering in WinForms MultiColumnComboBox?
Apply custom filter
In WinForms MultiColumnComboBox the rows can be filtered according to the text present in combo box by using the below code snippet.
C#
void multiColumnComboBox1_KeyUp(object sender, KeyEventArgs e) { selectedRows.Clear(); if (this.multiColumnComboBox1.TextBox.Text == "") { this.multiColumnComboBox1.DataSource = dt; } else { keypressed = e.KeyData.ToString().ToLower(); word = this.multiColumnComboBox1.Text; for (int i = 0; i <= this.multiColumnComboBox1.Items.Count - 1; i++) { object matchedRows = (this.multiColumnComboBox1.Items[i] as DataRowView).Row[0]; if (matchedRows != null && matchedRows.ToString().ToLower().Contains(word.ToString().ToLower())) { selectedRows.Add(this.multiColumnComboBox1.Items[i] as DataRowView); } } if (selectedRows.Count > 0) { this.multiColumnComboBox1.DataSource = selectedRows; this.multiColumnComboBox1.DroppedDown = false; this.multiColumnComboBox1.DroppedDown = true; this.multiColumnComboBox1.TextBox.Text = word; this.multiColumnComboBox1.SelectionStart = this.multiColumnComboBox1.Text.Length; this.multiColumnComboBox1.TextBox.SelectionLength = this.multiColumnComboBox1.Text.Length; } else { this.multiColumnComboBox1.DataSource = dt; } } |
VB
Private Sub multiColumnComboBox1_KeyUp(ByVal sender As Object, ByVal e As KeyEventArgs) selectedRows.Clear() If Me.multiColumnComboBox1.TextBox.Text = "" Then Me.multiColumnComboBox1.DataSource = dt Else keypressed = e.KeyData.ToString().ToLower() word = Me.multiColumnComboBox1.Text For i As Integer = 0 To Me.multiColumnComboBox1.Items.Count - 1 Dim matchedRows As Object = (TryCast(Me.multiColumnComboBox1.Items(i), DataRowView)).Row(0) If matchedRows IsNot Nothing AndAlso matchedRows.ToString().ToLower().Contains(word.ToString().ToLower()) Then selectedRows.Add(TryCast(Me.multiColumnComboBox1.Items(i), DataRowView)) End If Next i If selectedRows.Count > 0 Then Me.multiColumnComboBox1.DataSource = selectedRows Me.multiColumnComboBox1.DroppedDown = False Me.multiColumnComboBox1.DroppedDown = True Me.multiColumnComboBox1.TextBox.Text = word Me.multiColumnComboBox1.SelectionStart = Me.multiColumnComboBox1.Text.Length Me.multiColumnComboBox1.TextBox.SelectionLength = Me.multiColumnComboBox1.Text.Length Else Me.multiColumnComboBox1.DataSource = dt End If End If End Sub |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/MultiColumnComboBox-36716333.zip
Conclusion
I hope you enjoyed learning about how to implement custom filtering in WinForms MultiColumnComboBox.
You can refer to our WinForms MultiColumnComboBox feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!