)
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 customize the combobox button for combobox celltype in WinForms GridGroupingControl?

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 12, 2017 |
Last Revised Date: December 23, 2019

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.
void Grid_PrepareViewStyleInfo(Object sender, GridPrepareViewStyleInfoEventArgs e)
    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)

 

Screenshot

Customization of combobox button in GridGroupingControl

 

Samples:

C#: Customization of ComboBox Button CS

VB: Customization of ComboBox Button VB

Reference link: https://help.syncfusion.com/windowsforms/classic/gridgroupingcontrol/celltypes

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