How to change the column order of the WinForms GridListControl?
Change the column orders
You can change the column orders of a WinForms GridListControl by overriding the CreateGridColumn method in GridListControl class. By using this method, you can change the order of the columns as per your requirement. In the following sample, the columns are reordered from ParentID|Integer to Interger|ParentID.
C#
this.gridListControl1 = new reorder.MyGridListcontrol(); public class MyGridListcontrol : GridListControl { public MyGridListcontrol() : base() { } public override void CreateGridColumn(PropertyDescriptor pd, int column) { CurrencyManager cm = this.BindingContext[this.DataSource] as CurrencyManager; PropertyDescriptorCollection pdc = cm.GetItemProperties(); if (pdc != null) { if (column == 1) column = 2; else if (column == 2) column = 1; base.CreateGridColumn(pdc[column - 1], column); } } }
VB
Me.gridListControl1 = New reorder.MyGridListcontrol() public class MyGridListcontrol : GridListControl public MyGridListcontrol() MyBase.New() End Sub public override void CreateGridColumn(PropertyDescriptor pd, Integer column) Dim cm As CurrencyManager = TryCast(Me.BindingContext(Me.DataSource), CurrencyManager) Dim pdc As PropertyDescriptorCollection = cm.GetItemProperties() If pdc IsNot Nothing Then If column = 1 Then column = 2 ElseIf column = 2 Then column = 1 End If MyBase.CreateGridColumn(pdc(column - 1), column) End If End Sub End Class
The following screenshot displays the changed column order in the GridListControl.
Figure 1: Changed Column order in the GridListControl
Samples:
Conclusion
I hope you enjoyed learning about how to change the column order of the WinForms GridListControl.
You can refer to our WinForms GridListControl’s feature tour page to know about its other groundbreaking feature representations. You can also explore our WinForms GridListControl documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms GridListControl and other WinForms components.
If you have any queries or require clarifications, please let us know in the comment section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!