473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Move a data column in a datatable

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
5 11775
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
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
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
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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: em | last post by:
Hi all, I'm new to C# from VB6 and I'm playing around with SQL server. I can show the value of each field in my datatable with the following loop .... foreach(DataRow myRow in dt.Rows) {...
6
by: Hutty | last post by:
I've looked around and have yet to find anything that would answer my question regarding formating a column in a datagrid. My grid looks like this as far as data" AMHQCON|51300.01|-3147 The...
7
by: tshad | last post by:
Is there a way to move a row in a Datalist up or down without having to re-read the data? I have a datalist which has embedded Datagrids in it. I want to allow the user to move a row up or down...
1
by: Jon | last post by:
hi, I have 2 datatable, "dt1" and "dt2" I would like to know what is the best way to move the data across? I just want to move all the data from "dt1" which the "Category" column is "CatA" to...
2
by: Matthias | last post by:
Hi Team this may be a newbie question. I have searched the discussions before posting: I'd like to re-use a form instance to edit record details. My data binding (a DataTable bound to...
14
by: Peter | last post by:
Is there a fast way to move data from DataTable into double array, or do I have to spin through every record and column? I have five tables and I need to merge these tables column wise, each table...
10
by: D. Shane Fowlkes | last post by:
I have a function that is called in page_load and the purpose of this function is to look up basic data in a MSSQL table and return it in the form of a datatable. The page_load will read the data...
4
by: =?Utf-8?B?TWlrZSBE?= | last post by:
I read the CSV file into a DataTable. This is so I can fix invalid dates and other data I don't want in the database. Then I use SqlBulkCopy to insert the data into the SQL database. All the...
6
by: insirawali | last post by:
Hi all, I have this problem, i need to know is there a way i cn use the data adapter's update method in this scenario. i have 3 tables as below create table table1{ id1 int identity(1,1)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.