Moving Columns via ColumnName

Hi there,

Is there a way of moving column positions by using their column names?

I've found the following and it works but i need to use names instead of indexes.
<Code>
gridGroupingControl1.TableDescriptor.Columns.Move(3, 1);
</Code>

Regards,
James

2 Replies

PP Paulo P December 21, 2017 02:28 AM UTC

Hi James.
I think you can do it by using the TableDescriptor.VisibleColumns.IndexOf("ColumnName") property.
So, for instance if you want to move column "ProductName" position to "ProductDescription" position, you can achieve it through the following statement:
gridGroupingControl1.TableDescriptor.Columns.Move(gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("ProductName"), gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("ProductDescription"));


AR Arulpriya Ramalingam Syncfusion Team December 21, 2017 06:28 AM UTC

Hi James,  
  
Thanks for contacting Syncfusion support.  
  
As per our Current support, the GridGroupingControl does not have the direct support to move the columns by using name of the columns. Moreover, in GridGroupingControl, the columns are maintained in the Columns collection and VisibleColumns collection of GridTableDescriptor. As Paulo’s suggestion, you can make use of IndexOf() method ofVisibleColumns or Columns collection to retrieve the column index from the ColumnName and move the columns by using the retrieved index. Please make use of below code and refer to the sample.  
  
Code example  
  
//Suggestion 1  
//To retrieve the Column index from the Columns collection  
int columnIndex1 =this.gridGroupingControl1.TableDescriptor.Columns.IndexOf("CategoryID");  
int columnIndex2 =this.gridGroupingControl1.TableDescriptor.Columns.IndexOf("Description");  
  
//To Move the column  
this.gridGroupingControl1.TableDescriptor.Columns.Move(columnIndex1, columnIndex2);  
  
//Suggestion 2  
//To retrieve the Column index from the VisibleColumns collection  
int visibleColumn1 =this.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("CategoryID");  
int visibleColumn2 =this.gridGroupingControl1.TableDescriptor.VisibleColumns.IndexOf("Description");  
  
//To Move the column  
this.gridGroupingControl1.TableDescriptor.VisibleColumns.Move(visibleColumn1, visibleColumn2);  
  
  
  
Please refer to the below forum to retrieve the column index from the column name,  
  
  
Regards,  
Arulpriya  


Loader.
Up arrow icon