Articles in this section
Category / Section

Select the first row by using arrow key in WinForms GridListControl.

3 mins read

Selection

To select the first row using arrow key when the current selection is in the last row and viceversa of WinForms GridListControl, use TableControlCurrentCellKeyDown event. This handles the key down on the current cell and invokes the CurrentCellShowingDropDown event as the GridList control displays the dropdown grid to select the records. 

In the given sample, the GridList control is added as a column for the grid grouping control. 

C#

//Sets the CellType and data source for gridlistcontrol.
this.gridGroupingControl1.TableDescriptor.Columns[3].Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl;    
this.gridGroupingControl1.TableDescriptor.Columns[3].Appearance.AnyRecordFieldCell.DataSource = countries;            
this.gridGroupingControl1.TableDescriptor.Columns[3].Appearance.AnyRecordFieldCell.ValueMember = "CountryCode";
//Hooks the event in TableControl_CurrentCellShowingDropDown event
this.gridGroupingControl1.TableControlCurrentCellKeyDown += gridGroupingControl1_TableControlCurrentCellKeyDown;
void gridGroupingControl1_TableControlCurrentCellKeyDown(object sender, Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs e)
{
    //Gets the Currentcell rendere as the drop down gridlistcontrol renderer.
    GridDropDownGridListControlCellRenderer rend = e.TableControl.CurrentCell.Renderer as GridDropDownGridListControlCellRenderer;
    if (rend != null)
    {
        GridControl grid = rend.ListControlPart.Grid as GridControl;
        if (e.Inner.KeyCode == Keys.Down)
        {
            if (grid.CurrentCell.HasCurrentCellAt(grid.RowCount))
            {
                //Moves the selection to first record.
                grid.CurrentCell.MoveTo(GridRangeInfo.Row(0));
            }
        }
        if (e.Inner.KeyCode == Keys.Up)
        {
            if (!grid.CurrentCell.IsActive)
                grid.CurrentCell.MoveTo(1, 0);
            if (grid.CurrentCell.HasCurrentCellAt(1))
            {
                //moves the selection to last record.
                grid.CurrentCell.MoveTo(GridRangeInfo.Row(grid.RowCount));
            }
        }
    }
}

 

VB

'Sets the CellType and data source for gridlistcontrol
Me.gridGroupingControl1.TableDescriptor.Columns(3).Appearance.AnyRecordFieldCell.CellType = GridCellTypeName.GridListControl
Me.gridGroupingControl1.TableDescriptor.Columns(3).Appearance.AnyRecordFieldCell.DataSource = countries
Me.gridGroupingControl1.TableDescriptor.Columns(3).Appearance.AnyRecordFieldCell.ValueMember = "CountryCode"
'Hooks the event in TableControl_CurrentCellShowingDropDown event
Private Me.gridGroupingControl1.TableControlCurrentCellKeyDown += AddressOf gridGroupingControl1_TableControlCurrentCellKeyDown
Private Sub gridGroupingControl1_TableControlCurrentCellKeyDown(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableControlKeyEventArgs)
   'Gets the Currentcell rendere as the drop down gridlistcontrol renderer.
   Dim rend As GridDropDownGridListControlCellRenderer = TryCast(e.TableControl.CurrentCell.Renderer, GridDropDownGridListControlCellRenderer)
   If rend IsNot Nothing Then
      Dim grid As GridControl = TryCast(rend.ListControlPart.Grid, GridControl)
      If e.Inner.KeyCode = Keys.Down Then
         If grid.CurrentCell.HasCurrentCellAt(grid.RowCount) Then
            'Moves the selection to first record.
            grid.CurrentCell.MoveTo(GridRangeInfo.Row(0))
         End If
      End If
      If e.Inner.KeyCode = Keys.Up Then
         If Not grid.CurrentCell.IsActive Then
            grid.CurrentCell.MoveTo(1, 0)
         End If
         If grid.CurrentCell.HasCurrentCellAt(1) Then
            'moves the selection to last record.
            grid.CurrentCell.MoveTo(GridRangeInfo.Row(grid.RowCount))
         End If
      End If
   End If
End Sub

 

Note:

Fire the TableControlCurrentCellKeyDown event with in CurrentCellShowingDropDown event.

 

The following image displays the GridList control with the dropdown grid.

Select the data from dropdown list in WinForms GridListControl

Samples:

C#: SelectionInGridListControl

VB: SelectionInGridListControl

Conclusion

I hope you enjoyed learning about how to select the first row by using arrow key in WinForms GridListControl.

You can refer to our  WinForms GridListControl feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridListControl documentation to understand how to create and manipulate data.

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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied