How to make a ComboBox cell as case sensitive in WinForms GridGroupingControl?
Set ComboBox cell as case sensitive
The ComboBox
cell can be made as case sensitive by overriding the FindItem method
for custom CellRenderer(CustomComboBoxCellRenderer) to ignore the case
insensitive and override the ApplyFormattedText for 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.
C#
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);
}
}VB
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.
C#
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);
}
}VB
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: Set the CustomComboBoxCellModel into the default ComboBox cell.
GridControl
C#
this.gridControl1.Model.CellModels["ComboBox"] = new CustomComboBoxCellModel(this.gridControl1.Model);
this.gridControl1.ColStyles[1].CellType = GridCellTypeName.ComboBox;VB
Me.gridControl1.Model.CellModels("ComboBox") = New CustomComboBoxCellModel(Me.gridControl1.Model)
Me.gridControl1.ColStyles(1).CellType = GridCellTypeName.ComboBoxGridGroupingControl
C#
this.gridGroupingControl1.TableModel.CellModels["ComboBox"] = new CustomComboBoxCellModel(this.gridGroupingControl1.TableModel.Model);
this.gridGroupingControl1.TableDescriptor.Columns["Name"].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBox;VB
Me.gridGroupingControl1.TableModel.CellModels("ComboBox") = New CustomComboBoxCellModel(Me.gridGroupingControl1.TableModel.Model)
Me.gridGroupingControl1.TableDescriptor.Columns("Name").Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.ComboBoxThe below screenshot illustrates the comboBox cell as case sensitive in Grid and GridGroupingControl.
GridControl

GridGroupingControl

Samples:
GridControl
C#: GridControl with ComboBox CS
VB: GridControl with ComboBox VB
GridGroupingControl
C#: GridGroupingControl with ComboBox CS
VB: GridGroupingControl with ComboBox VB
Conclusion
I hope you enjoyed learning about how to make
a ComboBox cell case sensitive in GridGroupingControl.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!