Category / Section
How to set the properties of the embedded Grid in the GridListControl CellType in WinForms GridControl?
2 mins read
Embedded grid in GridListControl celltype
To set the properties of the embedded Grid in the GridListControl CellType, you need to handle the CurrentCellShowingDropDown event. In CurrentCellShowingDropDown event, cast the current cell’s renderer as GridDropDownGridListControlCellRenderer. By using the list control, set the embedded Grid properties. You can also set the number of rows that are to be visible in the drop-down.
Refer to the following code examples.
C#
//Hooks the CurrentCellShowingDropDown event in Form_Load()
this.gridControl1.CurrentCellShowingDropDown += gridControl1_CurrentCellShowingDropDown;
void gridControl1_CurrentCellShowingDropDown(object sender, GridCurrentCellShowingDropDownEventArgs e)
{
GridControlBase grid = sender as GridControlBase;
GridCurrentCell cc = grid.CurrentCell;
//Condition for checking the renderer whether it's a GridDropDownGridListControlCellRenderer.
if (cc.Renderer is GridDropDownGridListControlCellRenderer)
{
GridDropDownGridListControlCellRenderer cr = cc.Renderer as GridDropDownGridListControlCellRenderer;
//Sets the number of dropdown rows
((GridDropDownGridListControlPart)cr.ListControlPart).DropDownRows = 4;
// Adjust the properties in the Embedded Grid
cr.ListControlPart.Grid.ColWidths[1] = 30;
// hides the row one and two from the drop down
cr.ListControlPart.Grid.SetRowHidden(5, 6, true);
// sets the background color for the list drop down
cr.ListControlPart.BackColor = Color.Orange;
}
}
VB
'Hooks the CurrentCellShowingDropDown event in Form_Load()
Me.gridControl1.CurrentCellShowingDropDown += gridControl1_CurrentCellShowingDropDown
Private Sub gridControl1_CurrentCellShowingDropDown(ByVal sender As Object, ByVal e As GridCurrentCellShowingDropDownEventArgs)
Dim grid As GridControlBase = TryCast(sender, GridControlBase)
Dim cc As GridCurrentCell = grid.CurrentCell
'Condition for checking the renderer whether it's a GridDropDownGridListControlCellRenderer.
If TypeOf cc.Renderer Is GridDropDownGridListControlCellRenderer Then
Dim cr As GridDropDownGridListControlCellRenderer = TryCast(cc.Renderer, GridDropDownGridListControlCellRenderer)
'Sets the number of dropdown rows
CType(cr.ListControlPart, GridDropDownGridListControlPart).DropDownRows = 4
' Adjust the properties in the Embedded Grid
cr.ListControlPart.Grid.ColWidths(1) = 30
' hides the row one and two from the drop down
cr.ListControlPart.Grid.SetRowHidden(5, 6, True)
' sets the background color for the list drop down
cr.ListControlPart.BackColor = Color.Orange
End If
End Sub
Figure 1: GridListControl cell in a grid control
Samples:
Didn't find an answer?
Contact Support