We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Filter the Row in MultiColumnComboBox

Platform: WinForms |
Control: MultiColumnComboBox |
Published Date: November 19, 2014 |
Last Revised Date: November 19, 2014

How to apply custom filtering in MultiColumnComboBox?

 

In MultiColumnComboBox the rows can be filtered according to the text present in combo box by using the below code snippet.

 

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;

}

}

 

 

 

 

 

 

 

 

 

Code Snippet: [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 Link: http://www.syncfusion.com/downloads/support/directtrac/general/MultiColumnComboBox-36716333.zip

 

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon