How to make a ComboBox cell as case sensitive in WinForms GridControl?
Set the Combobox cell as case sensitive
The ComboBox cell can be made case sensitive by overriding the FindItem method for a custom CellRenderer(CustomComboBoxCellRenderer) to ignore the case insensitive and overriding the ApplyFormattedText for a custom CellModel(CustomComboBoxCellModel) to set the given text to the ComboBox.
The following
are the steps that need to be followed.
Step 1: Create a CustomComboBoxCellModel by deriving it from the GridComboBoxCellModel class.
public class CustomComboBoxCellModel : GridComboBoxCellModel
{
public CustomComboBoxCellModel(GridModel grid)
: base(grid)
{
AllowFloating = false;
ButtonBarSize = new Size(SystemInformation.VerticalScrollBarWidth, 0);
SupportsChoiceList = true;
}
GridComboBoxListBoxHelper listBox;
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new CustomComboBoxCellRenderer(control, this);
}
public override bool ApplyFormattedText(GridStyleInfo style, string text, int textInfo)
{
if (text.Length > 0 && text != null && (style.ChoiceList == null || style.ChoiceList.Count == 0))
{
if (style.DisplayMember != style.ValueMember)
{
style.CellValue = text;
return true;
}
}
return base.ApplyFormattedText(style, text, textInfo);
}
}Public Class CustomComboBoxCellModel
Inherits GridComboBoxCellModel
Public Sub New(ByVal grid As GridModel)
MyBase.New(grid)
AllowFloating = False
ButtonBarSize = New Size(SystemInformation.VerticalScrollBarWidth, 0)
SupportsChoiceList = True
End Sub
Private listBox As GridComboBoxListBoxHelper
Public Overrides Function CreateRenderer(ByVal control As GridControlBase) As GridCellRendererBase
Return New CustomComboBoxCellRenderer(control, Me)
End Function
Public Overrides Function ApplyFormattedText(ByVal style As GridStyleInfo, ByVal text As String, ByVal textInfo As Integer) As Boolean
If text.Length > 0 AndAlso text IsNot Nothing AndAlso (style.ChoiceList Is Nothing OrElse style.ChoiceList.Count = 0) Then
If style.DisplayMember <> style.ValueMember Then
style.CellValue = text
Return True
End If
End If
Return MyBase.ApplyFormattedText(style, text, textInfo)
End Function
End ClassStep 2: Create a CustomComboBoxCellRenderer from the GridComboBoxCellRenderer.
public class CustomComboBoxCellRenderer : GridComboBoxCellRenderer
{
public CustomComboBoxCellRenderer(GridControlBase grid, GridCellModelBase cellModel)
: base(grid, cellModel)
{
DropDownImp.InitFocusEditPart = true;
DropDownButton = new GridCellComboBoxButton(this);
}
public override int FindItem(string prefix, bool selectItem, int start, bool ignoreCase)
{
ignoreCase = false;
return base.FindItem(prefix, selectItem, start, ignoreCase);
}
}Public Class CustomComboBoxCellRenderer
Inherits GridComboBoxCellRenderer
Public Sub New(ByVal grid As GridControlBase, ByVal cellModel As GridCellModelBase)
MyBase.New(grid, cellModel)
DropDownImp.InitFocusEditPart = True
DropDownButton = New GridCellComboBoxButton(Me)
End Sub
Public Overrides Function FindItem(ByVal prefix As String, ByVal selectItem As Boolean, ByVal start As Integer, ByVal ignoreCase As Boolean) As Integer
ignoreCase = False
Return MyBase.FindItem(prefix, selectItem, start, ignoreCase)
End Function
End ClassStep 3: Create a CustomComboBoxCellRenderer from the GridComboBoxCellRenderer.
this.gridControl1.Model.CellModels["ComboBox"] = new CustomComboBoxCellModel(this.gridControl1.Model);
this.gridControl1.ColStyles[1].CellType = GridCellTypeName.ComboBox;Me.gridControl1.Model.CellModels("ComboBox") = New CustomComboBoxCellModel(Me.gridControl1.Model)
Me.gridControl1.ColStyles(1).CellType = GridCellTypeName.ComboBoxThe screenshot below displays the ComboBox cell as Case Sensitive.

Samples: