)
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 determine the Drop-Down items in a Grid Combo Box cell in WinForms GridControl?

Platform: WinForms |
Control: GridControl |
Published Date: April 30, 2011 |
Last Revised Date: December 18, 2019

Drop-down items in grid

You can set the DropDownRows property to control this. But it is buried a little deep, and generally requires an event handler to set it.

As, a single combo box cell control is shared among all combo box cells normally. And each cell can potentially have a different list and may require different drop-down rows.

Solution

To handle this, use the CurrentCellShowingDropdown event, and set the property there depending upon the exact row and column. Following are some code examples.

C#

//set the celltype into combobox.
this.gridControl1[6, 4].CellType = "ComboBox";
this.gridControl1[6, 4].CellValue = "None";
this.gridControl1[6, 4].ShowButtons = GridShowButtons.ShowCurrentCell;
this.gridControl1[6, 4].CellAppearance = GridCellAppearance.Raised;
this.gridControl1[6, 4].ChoiceList = items;
//Trigger the event
this.gridControl1.CurrentCellShowingDropDown += gridControl1_CurrentCellShowingDropDown;
void gridControl1_CurrentCellShowingDropDown(object sender, Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs e)
{
    GridControlBase cb = sender as GridControlBase;
    if (cb != null)
    {
        GridCurrentCell cc = cb.CurrentCell;
        GridComboBoxCellRenderer cr = cc.Renderer as GridComboBoxCellRenderer;
        //check the GridComboBoxCellRenderer is not null
        if (cr != null)
        {
            if (cc.RowIndex == 6)
                //Show the dropdown as 4 when the row index as 6
                ((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 4;
            else if (cc.RowIndex == 2)
                //Show the dropdown as 2 when the row index as 2
                ((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 2;
            //Show the dropdown as 6 when the row index as 4
            else ((GridComboBoxListBoxPart)cr.ListBoxPart).DropDownRows = 6;
        }
    }
}

VB

'set the celltype into combobox.
Me.gridControl1(6, 4).CellType = "ComboBox"
Me.gridControl1(6, 4).CellValue = "None"
Me.gridControl1(6, 4).ShowButtons = GridShowButtons.ShowCurrentCell
Me.gridControl1(6, 4).CellAppearance = GridCellAppearance.Raised
Me.gridControl1(6, 4).ChoiceList = items
'Trigger the event
Me.gridControl1.CurrentCellShowingDropDown += gridControl1_CurrentCellShowingDropDown
Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCurrentCellShowingDropDownEventArgs)
Dim cb As GridControlBase = TryCast(sender, GridControlBase)
If cb IsNot Nothing Then
    Dim cc As GridCurrentCell = cb.CurrentCell
    Dim cr As GridComboBoxCellRenderer = TryCast(cc.Renderer, GridComboBoxCellRenderer)
    'check the GridComboBoxCellRenderer is not null
    If cr IsNot Nothing Then
        If cc.RowIndex = 6 Then
            'Show the dropdown as 4 when the row index as 6
            CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 4
        ElseIf cc.RowIndex = 2 Then
        'Show the dropdown as 2 when the row index as 2
        CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 2
        'Show the dropdown as 6 when the row index as 4
        Else
            CType(cr.ListBoxPart, GridComboBoxListBoxPart).DropDownRows = 6
        End If
    End If
End If
End Sub

Samples:

C#: Dropdown_Control

VB: Dropdown_Control

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