|
1 | | -# How to differentiate combobox column from other columns in non-editable in view in winforms datagrid? |
2 | | -This example illustrates how to differentiate combobox column from other columns in non-editable in view in winforms datagrid |
| 1 | +# How to Differentiate Combobox Column from Other Columns in Non-editable in View in WinForms DataGrid? |
| 2 | + |
| 3 | +This example illustrates how to differentiate combobox column from other columns in non-editable in view in [WinForms DataGrid](https://www.syncfusion.com/winforms-ui-controls/datagrid) (SfDataGrid). |
| 4 | + |
| 5 | +Normally, the drop-down arrow for [GridComboBoxColumn](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataGrid.GridComboBoxColumn.html) 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 DataGrid. |
| 6 | + |
| 7 | +#### C# |
| 8 | + |
| 9 | +``` csharp |
| 10 | +public Form1() |
| 11 | +{ |
| 12 | + InitializeComponent(); |
| 13 | + this.sfDataGrid1.CellRenderers["ComboBox"] = new CustomComboBoxCellRenderer(); |
| 14 | +} |
| 15 | + |
| 16 | +public class CustomComboBoxCellRenderer : GridComboBoxCellRenderer |
| 17 | +{ |
| 18 | + protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, Syncfusion.WinForms.GridCommon.ScrollAxis.RowColumnIndex rowColumnIndex) |
| 19 | + { |
| 20 | + base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); |
| 21 | + var dropDownbuttonRect = new Rectangle(cellRect.X + cellRect.Width - 17, cellRect.Y + (cellRect.Height / 2), 8, 4); |
| 22 | + paint.DrawLine(new Pen(Color.Gray), dropDownbuttonRect.X, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width / 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height); |
| 23 | + paint.DrawLine(new Pen(Color.Gray), dropDownbuttonRect.X + dropDownbuttonRect.Width, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width / 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height); |
| 24 | + } |
| 25 | +} |
| 26 | +``` |
| 27 | + |
| 28 | +#### VB |
| 29 | + |
| 30 | +``` vb |
| 31 | +Public Sub New() |
| 32 | + InitializeComponent() |
| 33 | + Me.sfDataGrid1.CellRenderers("ComboBox") = New CustomComboBoxCellRenderer() |
| 34 | +End Sub |
| 35 | + |
| 36 | +Public Class CustomComboBoxCellRenderer |
| 37 | + Inherits GridComboBoxCellRenderer |
| 38 | + 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) |
| 39 | + MyBase.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex) |
| 40 | + Dim dropDownbuttonRect = New Rectangle(cellRect.X + cellRect.Width - 17, cellRect.Y + (cellRect.Height \ 2), 8, 4) |
| 41 | + paint.DrawLine(New Pen(Color.Gray), dropDownbuttonRect.X, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width \ 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height) |
| 42 | + paint.DrawLine(New Pen(Color.Gray), dropDownbuttonRect.X + dropDownbuttonRect.Width, dropDownbuttonRect.Y, dropDownbuttonRect.X + (dropDownbuttonRect.Width \ 2), dropDownbuttonRect.Y + dropDownbuttonRect.Height) |
| 43 | + End Sub |
| 44 | +End Class |
| 45 | +``` |
| 46 | + |
| 47 | + |
0 commit comments