Home All Groups Group Topic Archive Search About

How to add a column to the first position

Author
17 Oct 2006 9:24 PM
ad
I use the code below to add a columns to the columns of a table.
    Table1.Columns.Add("NewField", typeof(string));
But it always add the clolumn to the last position.
How can I add a column to the first position.

Author
17 Oct 2006 11:18 PM
Scott M.
The only way to do it is to make it first.  But, why do you need to adjust
the order of the columns anyway?  You can extract the data in any order you
need to.


Show quote
"ad" <fly***@wfes.tcc.edu.tw> wrote in message
news:Ou%23ZoKj8GHA.3740@TK2MSFTNGP05.phx.gbl...
>I use the code below to add a columns to the columns of a table.
>    Table1.Columns.Add("NewField", typeof(string));
> But it always add the clolumn to the last position.
> How can I add a column to the first position.
>
>
Author
18 Oct 2006 7:39 AM
Morten Wennevik
On Wed, 18 Oct 2006 01:18:31 +0200, Scott M. <s-mar@nospam.nospam> wrote:

> The only way to do it is to make it first.  But, why do you need to 
> adjust
> the order of the columns anyway?  You can extract the data in any order 
> you
> need to.
>
>

That is not correct.  You can reorder columns after they have been created 
by using SetOrdinal


Table1.Columns.Add("NewField", typeof(string)).SetOrdinal(0);


--
Happy Coding!
Morten Wennevik [C# MVP]
Author
18 Oct 2006 5:10 PM
Scott M.
This is only available in the 2.0 Framework.  I (correctly or incorrectly)
assumed the question was a 1.1 question. In 1.1, there is no way to re-order
the columns after they have been added.


Show quote
"Morten Wennevik" <MortenWenne***@hotmail.com> wrote in message
news:op.thlwwsaxklbvpo@tr024.bouvet.no...
> On Wed, 18 Oct 2006 01:18:31 +0200, Scott M. <s-mar@nospam.nospam> wrote:
>
>> The only way to do it is to make it first.  But, why do you need to
>> adjust
>> the order of the columns anyway?  You can extract the data in any order
>> you
>> need to.
>>
>>
>
> That is not correct.  You can reorder columns after they have been created
> by using SetOrdinal
>
>
> Table1.Columns.Add("NewField", typeof(string)).SetOrdinal(0);
>
>
> --
> Happy Coding!
> Morten Wennevik [C# MVP]
Author
18 Oct 2006 4:55 PM
Cor Ligthert [MVP]
Ad,

If I understand you right, than has the new DataView.ToTable an overloaded
method for this.

http://msdn2.microsoft.com/en-us/library/h2b6ehaa.aspx

I hope this helps,

Cor


Show quote
"ad" <fly***@wfes.tcc.edu.tw> schreef in bericht
news:Ou%23ZoKj8GHA.3740@TK2MSFTNGP05.phx.gbl...
>I use the code below to add a columns to the columns of a table.
>    Table1.Columns.Add("NewField", typeof(string));
> But it always add the clolumn to the last position.
> How can I add a column to the first position.
>
>

AddThis Social Bookmark Button