)
We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Platform: WinForms |
Control: GridGroupingControl |
Published Date: January 6, 2017 |
Last Revised Date: February 11, 2020

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

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon