Articles in this section
Category / Section

How to solve trimming of text in the dropdown of ComboBox cell?

2 mins read

By default, the text in the dropdown of ComboBox cell in GridDataBoundGrid control gets trimmed when the text has more letters. When you want to set the size of dropdown based on the text size, you can use TextRenderer.MeasureString() in the CurrentCellShowingDropDown event.

C#

void gridDataBoundGrid1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
    //Display the items without trimming.
    if (this.gridDataBoundGrid1.Model.CurrentCellRenderer != null && this.gridDataBoundGrid1.Model.CurrentCellRenderer is GridComboBoxCellRenderer)
    {
        GridComboBoxCellRenderer listRenderer =
(GridComboBoxCellRenderer)this.gridDataBoundGrid1.Model.CurrentCellRenderer;
        foreach (var item in items)
        {
            list.Add(TextRenderer.MeasureText(item, style.GdipFont as Font).Width);
        }
        list.Sort();
        e.Size =new System.Drawing.Size(list[list.Count - 1],list.Count*10);
    }
}

VB

Private Sub gridDataBoundGrid1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs)
  'display the items without trimming
  If Me.gridDataBoundGrid1.Model.CurrentCellRenderer IsNot Nothing AndAlso TypeOf    Me.gridDataBoundGrid1.Model.CurrentCellRenderer Is GridComboBoxCellRenderer Then
  Dim listRenderer As GridComboBoxCellRenderer = CType(Me.gridDataBoundGrid1.Model.CurrentCellRenderer, GridComboBoxCellRenderer)
    For Each item In items
      list.Add(TextRenderer.MeasureText(item, TryCast(style.GdipFont, Font)).Width)
        Next item
          list.Sort()
            e.Size = New System.Drawing.Size(list(list.Count - 1),list.Count*10)
  End If
End Sub

After applying the properties, the dropdown of ComboBox in GridDataBoundGrid is displayed in the following screenshot.

 

Figure 1: Output

Sample link:

C#: Dropdown Text

VB: Dropdown Text

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