)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to implement custom filtering in WinForms MultiColumnComboBox?

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

Apply custom filter

In 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: 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.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon