Articles in this section
Category / Section

How to make a ComboBox cell as case sensitive in WinForms GridControl and GridGroupingControl?

2 mins read

Set Combobox cell as case sensitive

The ComboBox cell can be make as case sensitive by override 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 CustomComboBoxCellModel by deriving it from 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 Class

Step 2: Create 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 Class

Step 3: Set the CustomComboBoxCellModel into 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.ComboBox

GridGroupingControl

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.ComboBox

Screenshot

GridControl

Show the combobox cell as case sensitive

GridGroupingControl

Show the combobox cell as case sensitive

Samples:

GridControl

C#: GridControl with ComboBox CS

VB: GridControl with ComboBox VB

GridGroupingControl

C#: GridGroupingControl with ComboBox CS

VB: GridGroupingControl with ComboBox VB

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