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 differentiate combobox column from other columns in non-editable display mode in WinForms DataGrid (SfDataGrid)?

Platform: WinForms |
Control: SfDataGrid |
Published Date: December 14, 2018 |
Last Revised Date: January 10, 2020

Differentiate combobox column from other columns

Normally, the drop-down arrow for GridComboBoxColumn will be shown only in the edit mode. You can differentiate the combo box column from other columns by showing the drop-down arrow in the display mode by creating custom renderer for the combo box column.

C#

public Form1()
{
    InitializeComponent();
    this.sfDataGrid1.CellRenderers["ComboBox"] = new CustomComboBoxCellRenderer();
}
 
public class CustomComboBoxCellRenderer : GridComboBoxCellRenderer
{
    protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex rowColumnIndex)
    {
        base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex);
        var dropDownbuttonRect = new Rectangle(cellRect.X + cellRect.Width - 17, cellRect.Y + (cellRect.Height / 2), 8, 4);
        paint.DrawLine(new Pen(Color.Gray), dropDownbuttonRect.X, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width / 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height);
        paint.DrawLine(new Pen(Color.Gray), dropDownbuttonRect.X + dropDownbuttonRect.Width, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width / 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height);
    }
}

VB

Public Sub New()
    InitializeComponent()
    Me.sfDataGrid1.CellRenderers("ComboBox") = New CustomComboBoxCellRenderer()
End Sub
 
Public Class CustomComboBoxCellRenderer
    Inherits GridComboBoxCellRenderer
    Protected Overrides Sub OnRender(ByVal paint As Graphics, ByVal cellRect As Rectangle, ByVal cellValue As String, ByVal style As CellStyleInfo, ByVal column As DataColumnBase, ByVal rowColumnIndex As Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex)
        MyBase.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex)
        Dim dropDownbuttonRect = New Rectangle(cellRect.X + cellRect.Width - 17, cellRect.Y + (cellRect.Height \ 2), 8, 4)
        paint.DrawLine(New Pen(Color.Gray), dropDownbuttonRect.X, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width \ 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height)
        paint.DrawLine(New Pen(Color.Gray), dropDownbuttonRect.X + dropDownbuttonRect.Width, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width \ 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height)
    End Sub
End Class

 

Differentiate the combobox column from other columns in non editable mode

Sample: How to differentiate combobox column from other columns in non-editable display mode?

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