Category / Section
How to display CheckBox type column in WinForms MultiColumnComboBox?
2 mins read
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

Figure 1. Adding CheckBox to the MultiColumnCombobox with image
Samples: