How to swap rows and columns in WinForms GridControl?
Swap rows and columns
Rows and columns can be swapped in the WinForms GridControl by handling the virtual events QueryCellInfo, SaveCellInfo, QueryRowCount, and QueryColCount. While swapping, the actual row count is assigned to the column count in the QueryColCount handler, and the actual column count is assigned to the row count in the QueryRowCount handler. Here, the GridControl.Data property is used. The GridData holds StyleInfoStore objects with cell-specific style properties. In the QueryCellInfo event handler, the style InfoObjects are provided in a swapped manner from the GridData, and in the SaveCellInfo event handler, they are saved in the correct order to the GridData.
void gridControl1_QueryCellInfo(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs e)
{
if(e.RowIndex >0 && e.ColIndex >0)
e.Style.ModifyStyle(this.gridControl1.Data[e.ColIndex, e.RowIndex], Syncfusion.Styles.StyleModifyType.Override);
}
private void gridControl1_QueryRowCount(object sender, GridRowColCountEventArgs e)
{
//In the QueryRowCount handler.
e.Count = this.gridControl1.Data.ColCount;
e.Handled = true;
}
void gridControl1_QueryColCount(object sender, GridRowColCountEventArgs e)
{
//In the QueryColCount handler.
e.Count = this.gridControl1.Data.RowCount;
e.Handled = true;
}
private void gridControl1_SaveCellInfo(object sender, GridSaveCellInfoEventArgs e)
{
//In the SaveCellInfo handler.
this.gridControl1.Data[e.ColIndex, e.RowIndex] = e.Style.Store;
}Private Sub gridControl1_QueryCellInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridQueryCellInfoEventArgs)
If e.RowIndex >0 AndAlso e.ColIndex >0 Then
e.Style.ModifyStyle(Me.gridControl1.Data(e.ColIndex, e.RowIndex), Syncfusion.Styles.StyleModifyType.Override)
End If
End Sub
Private Sub gridControl1_QueryRowCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
'In the QueryRowCount handler.
e.Count = Me.gridControl1.Data.ColCount
e.Handled = True
End Sub
Private Sub gridControl1_QueryColCount(ByVal sender As Object, ByVal e As GridRowColCountEventArgs)
'In the QueryColCount handler.
e.Count = Me.gridControl1.Data.RowCount
e.Handled = True
End Sub
Private Sub gridControl1_SaveCellInfo(ByVal sender As Object, ByVal e As GridSaveCellInfoEventArgs)
'In the SaveCellInfo handler.
Me.gridControl1.Data(e.ColIndex, e.RowIndex) = e.Style.Store
End SubThe screenshots below display the before and after swapping of rows and columns.

Figure 1: Before swap

Figure 2: After swap
Samples:
C#: SwapRowColumn
VB: SwapRowColumn