2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
Customize the dropdown height and widthYou 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.
Figure 1: Output Samples: C#: GridListControl VB: GridListControl |
2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
This page will automatically be redirected to the sign-in page in 10 seconds.