)
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 always display the WinForms GridListControl drop-down of the same size?

Platform: WinForms |
Control: GridListControl |
Published Date: May 6, 2015 |
Last Revised Date: January 2, 2020
Tags: dropdown, sizing

Customize the dropdown height and width

You can customize the dropdown height and width of the GridListControl cell by using the TableControlCurrentCellShowingDropDown event. In the given example, the size can be set for the dropdown based on the items count and its default height. Two columns are used here with the GridListControl cell type using QueryCellStyleInfo event and the sizes of those dropdowns have been changed within the TableControlCurrentCellShowingDropDown event.

C#

this.gridGroupingControl1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(gridGroupingControl1_QueryCellStyleInfo);
this.gridGroupingControl1.TableControlCurrentCellShowingDropDown += new GridTableControlCurrentCellShowingDropDownEventHandler(gridGroupingControl1_TableControlCurrentCellShowingDropDown);
void gridGroupingControl1_TableControlCurrentCellShowingDropDown(object sender, GridTableControlCurrentCellShowingDropDownEventArgs e)
{
    int defaultHeight = 18;
    //Dropdown size change for column 3.
    if (isitem1)
    {
        if (this.gridGroupingControl1.TableModel.CurrentCellRenderer != null && this.gridGroupingControl1.TableModel.CurrentCellRenderer is GridDropDownGridListControlCellRenderer)
        {                   
            GridDropDownGridListControlCellRenderer listRenderer =
(GridDropDownGridListControlCellRenderer)this.gridGroupingControl1.TableModel.CurrentCellRenderer;
            e.Inner.Size = new Size(200, (dr.Table.Rows.Count * defaultHeight));//Set the height based on the items.
            listRenderer.ListControlPart.ShowColumnHeader = false;
        }
    }
    //Dropdown size change for column 4.
    else if (isitem2)
        if (this.gridGroupingControl1.TableModel.CurrentCellRenderer != null && this.gridGroupingControl1.TableModel.CurrentCellRenderer is GridDropDownGridListControlCellRenderer)
        {
            GridDropDownGridListControlCellRenderer listRenderer =
(GridDropDownGridListControlCellRenderer)this.gridGroupingControl1.TableModel.CurrentCellRenderer;
            e.Inner.Size = new Size(300, (dr1.Table.Rows.Count * defaultHeight));//Set the height based on the items
            listRenderer.ListControlPart.ShowColumnHeader = false;
        }
}
bool isitem1, isitem2;
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)
{
    //GridListControl cell type assigned for column 4.
    if (e.TableCellIdentity.RowIndex > 2 && e.TableCellIdentity.ColIndex == 4)
    {
        e.Style.CellType = "GridListControl";
        e.Style.DataSource = this.ReturnATable();
        e.Style.DisplayMember = "LastName";
        isitem2 = true;
        isitem1 = false;
    }
    //GridListControl cell type assigned for column 3.
    if (e.TableCellIdentity.RowIndex > 2 && e.TableCellIdentity.ColIndex == 3)
    {
        e.Style.CellType = "GridListControl";
        e.Style.DataSource = this.table();
        e.Style.DisplayMember = "FirstName";
        isitem1 = true;
        isitem2 = false;
    }
}

 VB

'Trigger the Events.
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
AddHandler Me.gridGroupingControl1.TableControlCurrentCellShowingDropDown, AddressOf gridGroupingControl1_TableControlCurrentCellShowingDropDown
Private Sub gridGroupingControl1_TableControlCurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridTableControlCurrentCellShowingDropDownEventArgs)
            Dim defaultHeight As Integer = 18
    //Dropdown size change for column 3
            If isitem1 Then
                If Me.gridGroupingControl1.TableModel.CurrentCellRenderer IsNot Nothing AndAlso TypeOf Me.gridGroupingControl1.TableModel.CurrentCellRenderer Is GridDropDownGridListControlCellRenderer Then
                    Dim listRenderer As GridDropDownGridListControlCellRenderer = CType(Me.gridGroupingControl1.TableModel.CurrentCellRenderer, GridDropDownGridListControlCellRenderer)
                    e.Inner.Size = New Size(200, (dr.Table.Rows.Count * defaultHeight)) 'Set the height based on the items
                    listRenderer.ListControlPart.ShowColumnHeader = False
                End If
    //Drop down size change for column 4
            ElseIf isitem2 Then
                If Me.gridGroupingControl1.TableModel.CurrentCellRenderer IsNot Nothing AndAlso TypeOf Me.gridGroupingControl1.TableModel.CurrentCellRenderer Is GridDropDownGridListControlCellRenderer Then
                    Dim listRenderer As GridDropDownGridListControlCellRenderer = CType(Me.gridGroupingControl1.TableModel.CurrentCellRenderer, GridDropDownGridListControlCellRenderer)
                     e.Inner.Size = New Size(300, (dr1.Table.Rows.Count * defaultHeight)) 'Set the height based on the items
                      listRenderer.ListControlPart.ShowColumnHeader = False
          End If
      End If
End Sub
Private isitem1, isitem2 As Boolean
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As GridTableCellStyleInfoEventArgs)
          ‘GridListControl cell type assigned for column 4
           If e.TableCellIdentity.RowIndex > 2 AndAlso e.TableCellIdentity.ColIndex = 4 Then
                e.Style.CellType = "GridListControl"
                e.Style.DataSource = Me.ReturnATable()
                e.Style.DisplayMember = "LastName"
                isitem2 = True
                isitem1 = False
           End If
            ‘GridListControl cell type assigned for column 3
           If e.TableCellIdentity.RowIndex > 2 AndAlso e.TableCellIdentity.ColIndex = 3 Then
                e.Style.CellType = "GridListControl"
                e.Style.DataSource = Me.table()
                e.Style.DisplayMember = "FirstName"
                isitem1 = True
                isitem2 = False
           End If
End Sub

The following screenshot displays customized GridListControl dropdown height.

 

Customize the dropdown height and width

Figure 1: Output

Samples:

C#: GridListControl

VB: GridListControl

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