Articles in this section
Category / Section

How to differentiate combobox column from other columns in WinForms DataGrid?

1 min read

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 in WinForms DataGrid.


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

SampleHow to differentiate combobox column from other columns in non-editable display mode?


Conclusion

I hope you enjoyed learning about how to differentiate combobox column from other columns in WinForms DataGrid.

You can refer to our WinForms DataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

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