cancel
Showing results for 
Search instead for 
Did you mean: 

Move a Specific Column in a Collection

MassallysSilva
Level 3
Hi,

I have 16 columns but I want the last column to be between columns 6 and 7 for example, I already tried this by changing the code of the 'Merge Collection' how do I put it exactly where I want it?

------------------------------
Massallys Silva
------------------------------
1 BEST ANSWER

Helpful Answers

Glad that you were able to get it.
I edited the comment above to make it clear.

------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

View answer in original post

6 REPLIES 6

GopalBhaire
Level 10
Try this 
c1.Columns(colName).SetOrdinal(colIndex)
c3 = c1​
Edit: (for better understanding) 3 inputs c1=collection, colName=str, colIndex=Index output c3=collection and above 2 lines of code in code stage.

------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

It will be like this right?

For Each c As DataColumn in c2.Columns
    c1.Columns.Add(CloneColumn(c))
    
Next
 
For r As Integer = 0 To c1.Rows.Count + 1
    If r < c2.Rows.Count Then
        For Each c As DataColumn in c2.Columns
            c1.Rows(r)(c.ColumnName) = c2.Rows(r)(c.ColumnName)
        Next
    Else
        Exit For
    End If
Next
c1.Columns(colName).SetOrdinal(colIndex)
c3 = c1


------------------------------
Massallys Silva
------------------------------

23775.png
23776.pngI'm trying this but do not understand if i needed "colName" into input. 


------------------------------
Massallys Silva
------------------------------

This code does work it thank you

------------------------------
Massallys Silva
------------------------------

Glad that you were able to get it.
I edited the comment above to make it clear.

------------------------------
Gopal Bhaire
Analyst
Accenture
------------------------------

Yes, I saw. Thank you very much. You helped a lot!

------------------------------
Massallys Silva
------------------------------