By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,730 Members | 1,153 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,730 IT Pros & Developers. It's quick & easy.

Move a data column in a datatable

P: n/a
Tim
Hi,

I am trying to move a datacolumn in a datatable. What I have tried so
far is to create a new datacolumn set it equal to the one I want to
remove and then remove it, add another column and add it back again in
the place I want it.

tableStyle.MappingName = "DVGlobalPrices";

System.Data.DataColumn dCol = new DataColumn();
dCol = dvData.Table.Columns["CUR_new_price_1"];

dvData.Table.Columns.Remove(dCol);

if(dvData.Table.Columns["Button"] == null)
dvData.Table.Columns.Add("Button");

dvData.Table.Columns.Add(dCol);

However the column mapping seem to be lost as the whole column is now
displayed as (null) instead of the values.

Is this the best way to go about it? Is there another way? I am trying
to add a column that is not in the original dataview. If I append the
column to the end of the columns collection everything works fine, but I
would like to put it before the last column in the dataview.

Tim
Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
May I ask why the orders of the columns even matters?

As far as I know there is no way to move an existing column and preserve its
values.

"Tim" <ti**@peopletogo.com> wrote in message
news:S9******************@news20.bellglobal.com...
Hi,

I am trying to move a datacolumn in a datatable. What I have tried so far
is to create a new datacolumn set it equal to the one I want to remove and
then remove it, add another column and add it back again in the place I
want it.

tableStyle.MappingName = "DVGlobalPrices";

System.Data.DataColumn dCol = new DataColumn();
dCol = dvData.Table.Columns["CUR_new_price_1"];

dvData.Table.Columns.Remove(dCol);

if(dvData.Table.Columns["Button"] == null)
dvData.Table.Columns.Add("Button");

dvData.Table.Columns.Add(dCol);

However the column mapping seem to be lost as the whole column is now
displayed as (null) instead of the values.

Is this the best way to go about it? Is there another way? I am trying to
add a column that is not in the original dataview. If I append the column
to the end of the columns collection everything works fine, but I would
like to put it before the last column in the dataview.

Tim

Nov 21 '05 #2

P: n/a
I want to add two custom button columns at run time. They add just fine at
the end of the grid, but I want to put them next to the columns that are
associated with.

Hope you can help.

Tim

"Marina" <so*****@nospam.com> wrote in message
news:Om**************@TK2MSFTNGP15.phx.gbl...
May I ask why the orders of the columns even matters?

As far as I know there is no way to move an existing column and preserve
its values.

"Tim" <ti**@peopletogo.com> wrote in message
news:S9******************@news20.bellglobal.com...
Hi,

I am trying to move a datacolumn in a datatable. What I have tried so far
is to create a new datacolumn set it equal to the one I want to remove
and then remove it, add another column and add it back again in the place
I want it.

tableStyle.MappingName = "DVGlobalPrices";

System.Data.DataColumn dCol = new DataColumn();
dCol = dvData.Table.Columns["CUR_new_price_1"];

dvData.Table.Columns.Remove(dCol);

if(dvData.Table.Columns["Button"] == null)
dvData.Table.Columns.Add("Button");

dvData.Table.Columns.Add(dCol);

However the column mapping seem to be lost as the whole column is now
displayed as (null) instead of the values.

Is this the best way to go about it? Is there another way? I am trying to
add a column that is not in the original dataview. If I append the column
to the end of the columns collection everything works fine, but I would
like to put it before the last column in the dataview.

Tim


Nov 21 '05 #3

P: n/a
Ok, again, my question is, why does it matter where these columns are?

If you are displaying data in a grid you should be able to control where
what column is displayed anyway. I don't see why the actual ordering of the
columns makes a difference.

"Tim Cowan" <ti**************@peopletogo.com> wrote in message
news:HW******************@news20.bellglobal.com...
I want to add two custom button columns at run time. They add just fine at
the end of the grid, but I want to put them next to the columns that are
associated with.

Hope you can help.

Tim

"Marina" <so*****@nospam.com> wrote in message
news:Om**************@TK2MSFTNGP15.phx.gbl...
May I ask why the orders of the columns even matters?

As far as I know there is no way to move an existing column and preserve
its values.

"Tim" <ti**@peopletogo.com> wrote in message
news:S9******************@news20.bellglobal.com...
Hi,

I am trying to move a datacolumn in a datatable. What I have tried so
far is to create a new datacolumn set it equal to the one I want to
remove and then remove it, add another column and add it back again in
the place I want it.

tableStyle.MappingName = "DVGlobalPrices";

System.Data.DataColumn dCol = new DataColumn();
dCol = dvData.Table.Columns["CUR_new_price_1"];

dvData.Table.Columns.Remove(dCol);

if(dvData.Table.Columns["Button"] == null)
dvData.Table.Columns.Add("Button");

dvData.Table.Columns.Add(dCol);

However the column mapping seem to be lost as the whole column is now
displayed as (null) instead of the values.

Is this the best way to go about it? Is there another way? I am trying
to add a column that is not in the original dataview. If I append the
column to the end of the columns collection everything works fine, but I
would like to put it before the last column in the dataview.

Tim



Nov 21 '05 #4

P: n/a
Maybe, Marina, I am asking the wrong question. How do I change the display
order?

Do you know that answer to that one?

"Marina" <so*****@nospam.com> wrote in message
news:O0****************@TK2MSFTNGP10.phx.gbl...
Ok, again, my question is, why does it matter where these columns are?

If you are displaying data in a grid you should be able to control where
what column is displayed anyway. I don't see why the actual ordering of
the columns makes a difference.

"Tim Cowan" <ti**************@peopletogo.com> wrote in message
news:HW******************@news20.bellglobal.com...
I want to add two custom button columns at run time. They add just fine at
the end of the grid, but I want to put them next to the columns that are
associated with.

Hope you can help.

Tim

"Marina" <so*****@nospam.com> wrote in message
news:Om**************@TK2MSFTNGP15.phx.gbl...
May I ask why the orders of the columns even matters?

As far as I know there is no way to move an existing column and preserve
its values.

"Tim" <ti**@peopletogo.com> wrote in message
news:S9******************@news20.bellglobal.com...
Hi,

I am trying to move a datacolumn in a datatable. What I have tried so
far is to create a new datacolumn set it equal to the one I want to
remove and then remove it, add another column and add it back again in
the place I want it.

tableStyle.MappingName = "DVGlobalPrices";

System.Data.DataColumn dCol = new DataColumn();
dCol = dvData.Table.Columns["CUR_new_price_1"];

dvData.Table.Columns.Remove(dCol);

if(dvData.Table.Columns["Button"] == null)
dvData.Table.Columns.Add("Button");

dvData.Table.Columns.Add(dCol);

However the column mapping seem to be lost as the whole column is now
displayed as (null) instead of the values.

Is this the best way to go about it? Is there another way? I am trying
to add a column that is not in the original dataview. If I append the
column to the end of the columns collection everything works fine, but
I would like to put it before the last column in the dataview.

Tim



Nov 21 '05 #5

P: n/a
"Tim Cowan" <ti**************@peopletogo.com> wrote in message
news:tp******************@news20.bellglobal.com...
Maybe, Marina, I am asking the wrong question. How do I change the display
order?

Do you know that answer to that one?


Basically, it's the order they are in the Mapping Table. (Is this a
WebForm or WinForm application?)

--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.