> You just need to operate on DataGrid.Columns collection in code-behind.
> Look at the DataGridColumnCollection class, it has a few methods like
> AddAt that can help you.
> What I was hoping to do was to change the order of the columns already set
> up in the DataGrid object below, either in the Page_Load or Page_PreRender
> event. Since you can add a new column at the beginning of the column list
> using AddAt or Insert (which would in effect change the order of the
> columns) - is there a way to say move columns(2) to columns(1) some way?
Make a copy of columns(2), remove columns(2) from the grid and add it again
with AddAt(0). This will move columns(2) to columns(1).

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
>> You just need to operate on DataGrid.Columns collection in code-behind.
>> Look at the DataGridColumnCollection class, it has a few methods like
[quoted text clipped - 92 lines]
>>>
>>> Tom
tshad - 28 Aug 2007 17:22 GMT
>> What I was hoping to do was to change the order of the columns already
>> set up in the DataGrid object below, either in the Page_Load or
[quoted text clipped - 5 lines]
> Make a copy of columns(2), remove columns(2) from the grid and add it
> again with AddAt(0). This will move columns(2) to columns(1).
That's sounds like a great idea.
I understand how AddAt works , but how do you copy one column and remove
another?
CopyAt will copy all the columns into an array (I think) - but I am not sure
how I delete the columns that add the array back into the array.
Also, I plan to do this in my Page_Load/"not IsPostback" event. Will this
change carry over to my next page or do I need to do it again at each
PostBack?
Thanks,
Tom
>>> You just need to operate on DataGrid.Columns collection in code-behind.
>>> Look at the DataGridColumnCollection class, it has a few methods like
[quoted text clipped - 94 lines]
>>>>
>>>> Tom
Eliyahu Goldin - 28 Aug 2007 18:50 GMT
That's right. CopyAt is good for copying and RemoveAt for deleting. Than you
can AddAt an individual item from the array.

Signature
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
>>> What I was hoping to do was to change the order of the columns already
>>> set up in the DataGrid object below, either in the Page_Load or
[quoted text clipped - 121 lines]
>>>>>
>>>>> Tom
tshad - 28 Aug 2007 19:09 GMT
> That's right. CopyAt is good for copying and RemoveAt for deleting. Than
> you can AddAt an individual item from the array.
I assume you mean CopyTo?
I am having a problem doing the CopyTo. Do you have to do it after you
bind? I am just trying to change the order of the columns in the Page_Load
event before any binding is done.
I tried:
Dim theArray() as DataGridColumn
DataGrid2.Columns.CopyTo(theArray,0) -- error Object reference not set to
an instance of an object
I also tried:
Dim theArray(3) as DataGridColumn
DataGrid2.Columns.CopyTo(theArray,0) -- error
System.IndexOutOfRangeException: Index was outside the bounds of the array
Not sure what the problem is here.
Thanks,
Tom
>>>> What I was hoping to do was to change the order of the columns already
>>>> set up in the DataGrid object below, either in the Page_Load or
[quoted text clipped - 121 lines]
>>>>>>
>>>>>> Tom