How to focus on next cell when the ComboBox dropdown is closed in WinForms GridControl, GridGroupingControl and GridDataBoundGrid?
Change the focus to next cell
In GridControl, on closing the ComboBox dropdown, focus is maintained in a 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 a 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); }
VB
' 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
In the below image, after choosing a value for the first cell, current cell is moved to the next one.
For GridDataBoundGrid and GridGroupingControl, refer to the following code example respectively.
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); }
VB
‘hooking GridDataBoundGrid events. Private Me.gridDataBoundGrid1.Model.QueryCellInfo += New GridQueryCellInfoEventHandler(AddressOf Model_QueryCellInfo) Private Me.gridDataBoundGrid1.CurrentCellCloseDropDown += New PopupClosedEventHandler(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
GridGroupingControl
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 Private Me.gridGroupingControl1.QueryCellStyleInfo += AddressOf gridGroupingControl1_QueryCellStyleInfo 'Used for changing Currencell to next cell. Private 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
Samples:
C#: Move_nextcell_C#
VB: Move_nextcell_VB