2X faster development
The ultimate WinForms UI toolkit to boost your development speed.
SelectionYou can select the entire column in DataGrid using the SfDataGrid.SelectCells method. You should set the SfDataGrid.SelectionUnit property as Cell or Any and the SfDataGrid.SelectionMode property as Extended or Multiple for selecting the entire column. This column selection can be performed when clicking the column header using the SfDataGrid.CellClick event. C# public Form1() { InitializeComponent(); this.sfDataGrid.SelectionUnit = SelectionUnit.Cell; this.sfDataGrid.SelectionMode = GridSelectionMode.Extended; this.sfDataGrid.CellClick += sfDataGrid_CellClick; } void sfDataGrid_CellClick(object sender, Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs e) { if (e.DataRow.RowType == RowType.HeaderRow && this.sfDataGrid.View.TopLevelGroup == null) { var firstRowDate = this.sfDataGrid.View.Records[0]; var lastRowData = this.sfDataGrid.View.Records[this.sfDataGrid.View.Records.Count - 1]; var column = e.DataColumn.GridColumn; if (firstRowDate != null && lastRowData != null) { this.sfDataGrid.ClearSelection(); this.sfDataGrid.SelectCells(firstRowDate, column, lastRowData, column); } } } VB Public Sub New() InitializeComponent() Dim data = New OrderInfoCollection() sfDataGrid.DataSource = data.OrdersListDetails Me.sfDataGrid.AllowSorting = False Me.sfDataGrid.SelectionUnit = SelectionUnit.Cell Me.sfDataGrid.SelectionMode = GridSelectionMode.Extended AddHandler Me.sfDataGrid.CellClick, AddressOf sfDataGrid_CellClick End Sub Private Sub sfDataGrid_CellClick(ByVal sender As Object, ByVal e As Syncfusion.WinForms.DataGrid.Events.CellClickEventArgs) If e.DataRow.RowType = RowType.HeaderRow AndAlso Me.sfDataGrid.View.TopLevelGroup Is Nothing Then Dim firstRowDate = Me.sfDataGrid.View.Records(0) Dim lastRowData = Me.sfDataGrid.View.Records(Me.sfDataGrid.View.Records.Count - 1) Dim column = e.DataColumn.GridColumn If firstRowDate IsNot Nothing AndAlso lastRowData IsNot Nothing Then Me.sfDataGrid.ClearSelection() Me.sfDataGrid.SelectCells(firstRowDate, column, lastRowData, column) End If End If End Sub
Sample: WF Reference link: https://help.syncfusion.com/windowsforms/datagrid/selection |
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.