How to reorder SFDataGrid Columns

Hello,

I've created an UnboundColumn in my SFDataGrid.

It load correctly and displays data correctly.

But, it load as the first column in my datagrid.

How do I reorder it to show as last column in datagrid?

This is my UnboundColumn...

GridUnboundColumn column = new GridUnboundColumn
            {
                CaseSensitive = false,
                AllowEditing = false,
                MappingName = "Days",
                HeaderText = "Days",
                Expression = userInfo.GetDias.ToString(),
                CellStyle = new CellStyleInfo() { BackColor = Color.LightGray, TextColor = Color.DarkBlue, HorizontalAlignment = HorizontalAlignment.Right }
            };
            data.Columns.Add(column);

Thanks.

3 Replies

AA Arulraj A Syncfusion Team August 17, 2018 12:27 PM UTC

Hi Carlos, 
 
Thanks for contacting Syncfusion support. 
   
If you want to add the GridUnboundColumn as a last column, you have to add the GridUnboundColumn after setting the SfDataGrid.DataSource while enabling the SfDataGrid.AutoGenerateColumns. Please refer the below code example, 
 
Code Example 
ProductSalesDetailsCollection data = new ProductSalesDetailsCollection(); 
sfDataGrid.DataSource = data.SalesInfo; 
 
GridUnboundColumn column = new GridUnboundColumn(); 
column.CaseSensitive = false; 
column.AllowEditing = false; 
column.MappingName = "GrandTotal"; 
column.HeaderText = "Grand Total"; 
column.Expression = "Quantity*Amount"; 
column.Format = "{0:C}"; 
sfDataGrid.Columns.Add(column); 
 
Otherwise, after add the GridUnboundColumn you can move the column to the last position. Please refer the below code example 
 
Code Example 
ProductSalesDetailsCollection data = new ProductSalesDetailsCollection(); 
GridUnboundColumn column = new GridUnboundColumn(); 
column.CaseSensitive = false; 
column.AllowEditing = false; 
column.MappingName = "GrandTotal"; 
column.HeaderText = "Grand Total"; 
column.Expression = "Quantity*Amount"; 
column.Format = "{0:C}"; 
sfDataGrid.Columns.Add(column); 
sfDataGrid.DataSource = data.SalesInfo; 
sfDataGrid.Columns.Move(0, sfDataGrid.Columns.Count-1); 
 
 
Arulraj A 



CF Carlos Ferreira August 18, 2018 10:42 PM UTC

Thanks. That worked!


AA Arulraj A Syncfusion Team August 20, 2018 07:16 AM UTC

Hi Carlos, 

We are glad to know that the reported problem has been resolved. Please let us know if you need any further assistance on this. 

We are happy to help you. 

Arulraj A 


Loader.
Up arrow icon