Articles in this section

How to customize the ComboBox button for ComboBox celltype in WinForms GridGroupingControl?

Customize the combobox button


By default, ComboBox dropdown appearance cannot be customized. In order to customize the ComboBox appearance, the GridListControl cell type can be used instead of using the ComboBox cell type. This can be enabled by disabling the EnableLegacyStyle property or using the GridListControl cell type.

Please make use of the below customization to customize the appearance,

ComboBox Button Customization


The DrawCellButtonBackground event can be used to customize the dropdown button of the cell. 

 

C#

//Triggering the event.
this.gridGroupingControl1.TableControl.DrawCellButtonBackground += new GridDrawCellButtonBackgroundEventHandler(TableControl_DrawCellButtonBackground);
 
//Event customization. 
void TableControl_DrawCellButtonBackground(object sender, GridDrawCellButtonBackgroundEventArgs e)
{
    if (e.Style.CellType == GridCellTypeName.ComboBox)
    {
        ThemedComboBoxDrawing.DropDownState btnState = ThemedComboBoxDrawing.DropDownState.Normal;
        int rowIndex = e.Style.CellIdentity.RowIndex;
        int colIndex = e.Style.CellIdentity.ColIndex;

        bool isHovering = e.Button.IsHovering(rowIndex, colIndex);
        bool isMouseDown = e.Button.IsMouseDown(rowIndex, colIndex);

        bool disabled = !e.Style.Clickable;

        if (disabled)
        {
            btnState = ThemedComboBoxDrawing.DropDownState.Disabled;
        }
        else if (isMouseDown)
        {
            btnState = ThemedComboBoxDrawing.DropDownState.Pressed;
        }
        else if (isHovering)
        {
            btnState = ThemedComboBoxDrawing.DropDownState.Hot;
        }

        //Customize the ComboBox Button.   
        this.gridGroupingControl1.TableModel.Options.GridVisualStylesDrawing.DrawComboBoxStyle(e.Graphics, e.Button.Bounds, btnState, Color.Gray);
        Bitmap bitmap = new Bitmap(@"..\..\Resources\down.png");

        //Customize the icon of ComboBox.
        iconPaint.PaintIcon(e.Graphics, e.Button.Bounds, Point.Empty, bitmap, Color.Black);
        e.Cancel = true;
    }
}
VB
'Triggering the event.
AddHandler gridGroupingControl1.TableControl.DrawCellButtonBackground, AddressOf TableControl_DrawCellButtonBackground
 
'Event customization.
Private Sub TableControl_DrawCellButtonBackground(ByVal sender As Object, ByVal e As GridDrawCellButtonBackgroundEventArgs)
    If e.Style.CellType Is GridCellTypeName.ComboBox Then
        Dim btnState As ThemedComboBoxDrawing.DropDownState = ThemedComboBoxDrawing.DropDownState.Normal
        Dim rowIndex As Integer = e.Style.CellIdentity.RowIndex
        Dim colIndex As Integer = e.Style.CellIdentity.ColIndex

        Dim isHovering As Boolean = e.Button.IsHovering(rowIndex, colIndex)
        Dim isMouseDown As Boolean = e.Button.IsMouseDown(rowIndex, colIndex)

        Dim disabled As Boolean = Not e.Style.Clickable

        If disabled Then
            btnState = ThemedComboBoxDrawing.DropDownState.Disabled
        ElseIf isMouseDown Then
            btnState = ThemedComboBoxDrawing.DropDownState.Pressed
        ElseIf isHovering Then
            btnState = ThemedComboBoxDrawing.DropDownState.Hot
        End If

        'Customize the ComboBox Button.
        Me.gridGroupingControl1.TableModel.Options.GridVisualStylesDrawing.DrawComboBoxStyle(e.Graphics, e.Button.Bounds, btnState, Color.Gray)
        Dim bitmap As New Bitmap("..\..\Resources\down.png")
        'Customize the icon of ComboBox.
        iconPaint.PaintIcon(e.Graphics, e.Button.Bounds, Point.Empty, bitmap, Color.Black)
        e.Cancel = True
    End If
End Sub
Dropdown customization

The drop-down part can be customized by using the PrepareViewStyleInfo event of the GridListControl cell.

 

C#

GridCellRendererBase cellRenderer = this.gridGroupingControl1.TableControl.CellRenderers["ComboBox"];
renderer = (cellRenderer as GridDropDownGridListControlCellRenderer);

//Triggering the event of combobox cell renderer
renderer.ListControlPart.Grid.PrepareViewStyleInfo += new GridPrepareViewStyleInfoEventHandler(Grid_PrepareViewStyleInfo);
 
//Event customization.
void Grid_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)
{
    e.Style.TextColor = Color.White;

    if (renderer.ListControlPart.Grid.CurrentCell.RowIndex == e.RowIndex)
    {
        e.Style.BackColor = Color.PaleGreen;
    }

    e.Style.Font.Facename = "Segoe UI";
    e.Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Green);
}
VB
Dim cellRenderer As GridCellRendererBase = Me.gridGroupingControl1.TableControl.CellRenderers("ComboBox")
renderer = (TryCast(cellRenderer, GridDropDownGridListControlCellRenderer))

'Triggering the event of combobox cell renderer
AddHandler renderer.ListControlPart.Grid.PrepareViewStyleInfo, AddressOf Grid_PrepareViewStyleInfo
 
' Event customization
Private Sub Grid_PrepareViewStyleInfo(ByVal sender As Object, ByVal e As GridPrepareViewStyleInfoEventArgs)
    
    e.Style.TextColor = Color.White

    If renderer.ListControlPart.Grid.CurrentCell.RowIndex = e.RowIndex Then
        e.Style.BackColor = Color.PaleGreen
    End If

    e.Style.Font.Facename = "Segoe UI"
    e.Style.Borders.Bottom = New GridBorder(GridBorderStyle.Solid, Color.Green)
End Sub
The screenshot below illustrates the customization of the ComboBox button.

Customization of combobox button in GridGroupingControl

 

Samples:

C#: Customization of ComboBox Button CS

VB: Customization of ComboBox Button VB

 

Reference Link: Getting Started

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied