How to focus on next cell when ComboBox dropdown is closed in WinForms GridGroupingControl?
Change the focus to next cell
In WinForms GridGroupingControl, when closing the ComboBox dropdown, focus is maintained in the same cell. You can change the focus to the next cell while closing the dropdown in the GridControl by using the CurrentCell.MoveTo method and set the focus by using the GridSetCurrentCellOptions property. The following code examples explain how to focus on the next cell in the CurrentCellCloseDropDown event.
C#
// setting ComboBox for first column.
GridStyleInfo style = this.gridControl1.ColStyles[1] as GridStyleInfo;
style.CellType = "ComboBox";
style.ChoiceList = items;
style.DropDownStyle = GridDropDownStyle.Exclusive;
style.ShowButtons = GridShowButtons.Show;
//hooking CurrentCellCloseDropDown event.
this.gridControl1.CurrentCellCloseDropDown += new PopupClosedEventHandler(gridControl1_CurrentCellCloseDropDown);
void gridControl1_CurrentCellCloseDropDown(object sender, PopupClosedEventArgs e)
{
GridCurrentCell cc = this.gridControl1.CurrentCell;
// setting focus to the next cell.
this.gridControl1.CurrentCell.MoveTo(cc.RowIndex, cc.ColIndex + 1, GridSetCurrentCellOptions.SetFocus);
}
' setting ComboBox for first column.
Private style As GridStyleInfo = TryCast(Me.gridControl1.ColStyles(1), GridStyleInfo)
style.CellType = "ComboBox"
style.ChoiceList = items
style.DropDownStyle = GridDropDownStyle.Exclusive
style.ShowButtons = GridShowButtons.Show
'hooking CurrentCellCloseDropDown event.
AddHandler gridControl1.CurrentCellCloseDropDown, AddressOf gridControl1_CurrentCellCloseDropDown
Private Sub gridControl1_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As PopupClosedEventArgs)
Dim cc As GridCurrentCell = Me.gridControl1.CurrentCell
'setting focus to the next cell
Me.gridControl1.CurrentCell.MoveTo(cc.RowIndex,cc.ColIndex+1, GridSetCurrentCellOptions.SetFocus)
End Sub
Note:
For GridDataBoundGrid and GridGroupingControl, refer to the following code examples.
GridDataBoundGrid
C#
// hooking GridDataBoundGrid events.
this.gridDataBoundGrid1.Model.QueryCellInfo += new GridQueryCellInfoEventHandler(Model_QueryCellInfo);
this.gridDataBoundGrid1.CurrentCellCloseDropDown += new PopupClosedEventHandler(gridDataBoundGrid1_CurrentCellCloseDropDown);
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.ColIndex > 0 && e.RowIndex == 0)
{
int colIndex2 = this.gridDataBoundGrid1.Binder.NameToColIndex("Column4");
if (colIndex2 == e.ColIndex)
{
e.Style.BackColor = Color.White;
e.Style.CellType = "ComboBox";
e.Style.ChoiceList = items;
e.Style.CellAppearance = GridCellAppearance.Raised;
e.Style.Enabled = true;
}
}
}
void gridDataBoundGrid1_CurrentCellCloseDropDown(object sender, PopupClosedEventArgs e)
{
GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell;
// setting focus to the next cell.
this.gridDataBoundGrid1.CurrentCell.MoveTo(cc.RowIndex, cc.ColIndex + 1, GridSetCurrentCellOptions.SetFocus);
}
'hooking GridDataBoundGrid events.
AddHandler Me.gridDataBoundGrid1.Model.QueryCellInfo, AddressOf Model_QueryCellInfo
AddHandler Me.gridDataBoundGrid1.CurrentCellCloseDropDown, AddressOf gridDataBoundGrid1_CurrentCellCloseDropDown
Private Sub Model_QueryCellInfo(ByVal sender As Object, ByVal e As GridQueryCellInfoEventArgs)
If e.ColIndex > 0 AndAlso e.RowIndex = 0 Then
Dim colIndex2 As Integer = Me.gridDataBoundGrid1.Binder.NameToColIndex("Column4")
If colIndex2 = e.ColIndex Then
e.Style.BackColor = Color.White
e.Style.CellType = "ComboBox"
e.Style.ChoiceList = items
e.Style.CellAppearance = GridCellAppearance.Raised
.Style.Enabled = True
End If
End If
End Sub
Private Sub gridDataBoundGrid1_CurrentCellCloseDropDown(ByVal sender As Object, ByVal e As PopupClosedEventArgs)
Dim cc As GridCurrentCell = Me.gridDataBoundGrid1.CurrentCell
'setting focus to the next cell.
Me.gridDataBoundGrid1.CurrentCell.MoveTo(cc.RowIndex, cc.ColIndex + 1, GridSetCurrentCellOptions.SetFocus)
End Sub
C#
// used to set Cell Type
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo;
//used for changing Currencell to next cell.
this.gridGroupingControl1.TableControlCurrentCellCloseDropDown += gridGroupingControl1_TableControlCurrentCellCloseDropDown;
void gridGroupingControl1_QueryCellStyleInfo(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs e)
{
//Condition for checking the column header cell named 'Column4'
if (e.TableCellIdentity.Column != null && e.TableCellIdentity.Column.Name == "Column4")
{
e.Style.CellType = "ComboBox";
e.Style.ChoiceList = items;
}
}
void gridGroupingControl1_TableControlCurrentCellCloseDropDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlPopupClosedEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
e.TableControl.CurrentCell.MoveTo(cc.RowIndex, cc.ColIndex + 1, GridSetCurrentCellOptions.SetFocus);
}
VB
' used to set Cell Type
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
'Used for changing Currencell to next cell.
AddHandler Me.gridGroupingControl1.TableControlCurrentCellCloseDropDown, AddressOf gridGroupingControl1_TableControlCurrentCellCloseDropDown
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
'Condition for checking the column header cell named 'Column4'
If e.TableCellIdentity.Column IsNot Nothing AndAlso e.TableCellIdentity.Column.Name = "Column4" Then
e.Style.CellType = "ComboBox"
e.Style.ChoiceList = items
End If
End Sub
Private Sub gridGroupingControl1_TableControlCurrentCellCloseDropDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlPopupClosedEventArgs)
Dim cc As GridCurrentCell = e.TableControl.CurrentCell
e.TableControl.CurrentCell.MoveTo(cc.RowIndex, cc.ColIndex + 1, GridSetCurrentCellOptions.SetFocus)
End Sub
C#: Move_nextcell_C#
VB: Move_nextcell_VB
Conclusion
I hope you
enjoyed learning about how to focus on next cell when the ComboBox
dropdown is closed in GridControl, GridGroupingControl and GridDataBoundGrid.
You can refer to our WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!