Articles in this section
Category / Section

How to swap rows and columns in WinForms GridControl?

2 mins read

Swap rows and columns

Rows and columns can be swapped in the 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 QuerRowCount 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 Sub

Before swap

Figure 1: Before swap

After swap

Figure 2: After swap


C#: SwapRowColumn

VB: SwapRowColumn

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