)
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 display CheckBox type column in WinForms MultiColumnComboBox?

Platform: WinForms |
Control: MultiColumnComboBox |
Published Date: April 13, 2016 |
Last Revised Date: January 6, 2020

Display checkbox type column

In MultiColumnComboBox, GridListControl has been used as Popup Control. It is possible to display CheckBox in GridListControl and maintain its Check state based on user selection, by handling its events named SelectionChanged and QueryCellInfo.

 

SelectionChanged - This event will be triggered when the Selected value is changed in MultiColumnComboBox.

 

QueryCellInfo - This event will be triggered when the GridListControl is displayed.

 

C#

void multiColumnComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
      int selectedindex = this.multiColumnComboBox1.SelectedIndex + 1;
      //To check and uncheck the textbox text
      if ((this.multiColumnComboBox1.ListControl as GridListControl).Grid.Model[selectedindex, 1].CellType == GridCellTypeName.CheckBox)
      {
          foreach (DataRow row in dt.Rows)
          {
            if (row["FirstName"].ToString() == (this.multiColumnComboBox1.ListControl as GridListControl).Grid.Model[selectedindex, 2].Text)
            {
                if (row["CheckBox"].ToString() == "true")
                {
                    row["CheckBox"] = "false";
                }
                 else
                        {
                            row["CheckBox"] = "true";
                        }
                    }
                }
            }
            this.multiColumnComboBox1.Text = "";
            foreach (DataRow row in dt.Rows)
            {
                if (row["CheckBox"].ToString() == "true" && !this.multiColumnComboBox1.Text.Contains(row["place"].ToString()))
                {
                    this.multiColumnComboBox1.Text += row["place"].ToString() + ",";
                }
            }
         
        }        
void Grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
     if (e.ColIndex == 1 && e.RowIndex > 0)
     {
        // e.Style.CellValue = true;
         //To change the cell type as CheckBox
         e.Style.CheckBoxOptions = new GridCheckBoxCellInfo("true", "false", "",true);
         e.Style.CellType = GridCellTypeName.CheckBox;
        }
}

 

VB

Private Sub multiColumnComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
    Dim selectedindex As Integer = Me.multiColumnComboBox1.SelectedIndex + 1
    'To check and uncheck the textbox text
    If(TryCast(Me.multiColumnComboBox1.ListControl,GridListControl)).Grid.Model(selectedindex, 1).CellType Is GridCellTypeName.CheckBox Then
      For Each row As DataRow In dt.Rows
         If row("FirstName").ToString() = (TryCast(Me.multiColumnComboBox1.ListControl, GridListControl)).Grid.Model(selectedindex, 2).Text Then
 If row("CheckBox").ToString() = "true" Then
    row("CheckBox") = "false"
 Else
    row("CheckBox") = "true"
 End If
         End If
      Next row
    End If
    Me.multiColumnComboBox1.Text = ""
    For Each row As DataRow In dt.Rows
       If row("CheckBox").ToString() = "true" AndAlso (Not  Me.multiColumnComboBox1.Text.Contains(row("place").ToString())) Then
          Me.multiColumnComboBox1.Text += row("place").ToString() & ","
       End If
    Next row
End Sub
 
Private Sub Grid_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
    If e.ColIndex = 1 AndAlso e.RowIndex > 0 Then
      ' e.Style.CellValue = true;
      'To change the cell type as CheckBox
      e.Style.CheckBoxOptions = New GridCheckBoxCellInfo("true", "false", "", True)
      e.Style.CellType = GridCellTypeName.CheckBox
    End If
End Sub

                                                        Adding checkbox to the MultiColumnComboBox with image

Figure 1. Adding CheckBox to the MultiColumnCombobox with image

Samples:

C#:How to add CheckBox in the MultiColumnCombobox C#

VB: How to add CheckBox in the MultiColumnCombobox VB

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