473,748 Members | 7,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Mapp ingName = "DVGlobalPrices ";

System.Data.Dat aColumn dCol = new DataColumn();
dCol = dvData.Table.Co lumns["CUR_new_price_ 1"];

dvData.Table.Co lumns.Remove(dC ol);

if(dvData.Table .Columns["Button"] == null)
dvData.Table.Co lumns.Add("Butt on");

dvData.Table.Co lumns.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 11796
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**@peopletog o.com> wrote in message
news:S9******** **********@news 20.bellglobal.c om...
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.Mapp ingName = "DVGlobalPrices ";

System.Data.Dat aColumn dCol = new DataColumn();
dCol = dvData.Table.Co lumns["CUR_new_price_ 1"];

dvData.Table.Co lumns.Remove(dC ol);

if(dvData.Table .Columns["Button"] == null)
dvData.Table.Co lumns.Add("Butt on");

dvData.Table.Co lumns.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******** ******@TK2MSFTN GP15.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**@peopletog o.com> wrote in message
news:S9******** **********@news 20.bellglobal.c om...
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.Mapp ingName = "DVGlobalPrices ";

System.Data.Dat aColumn dCol = new DataColumn();
dCol = dvData.Table.Co lumns["CUR_new_price_ 1"];

dvData.Table.Co lumns.Remove(dC ol);

if(dvData.Table .Columns["Button"] == null)
dvData.Table.Co lumns.Add("Butt on");

dvData.Table.Co lumns.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.c om> wrote in message
news:HW******** **********@news 20.bellglobal.c om...
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******** ******@TK2MSFTN GP15.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**@peopletog o.com> wrote in message
news:S9******** **********@news 20.bellglobal.c om...
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.Mapp ingName = "DVGlobalPrices ";

System.Data.Dat aColumn dCol = new DataColumn();
dCol = dvData.Table.Co lumns["CUR_new_price_ 1"];

dvData.Table.Co lumns.Remove(dC ol);

if(dvData.Table .Columns["Button"] == null)
dvData.Table.Co lumns.Add("Butt on");

dvData.Table.Co lumns.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******** ********@TK2MSF TNGP10.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.c om> wrote in message
news:HW******** **********@news 20.bellglobal.c om...
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******** ******@TK2MSFTN GP15.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**@peopletog o.com> wrote in message
news:S9******** **********@news 20.bellglobal.c om...
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.Mapp ingName = "DVGlobalPrices ";

System.Data.Dat aColumn dCol = new DataColumn();
dCol = dvData.Table.Co lumns["CUR_new_price_ 1"];

dvData.Table.Co lumns.Remove(dC ol);

if(dvData.Table .Columns["Button"] == null)
dvData.Table.Co lumns.Add("Butt on");

dvData.Table.Co lumns.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.c om> wrote in message
news:tp******** **********@news 20.bellglobal.c om...
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
1442
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) { foreach(DataColumn myCol in dt.Columns) {
6
3838
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 first two columns are pretty much text column, but subsequent columns 1-12 are numerical. I'm trying to get the thousand separator to work. Any ideas?
7
3104
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 by just pushing a button and have the page post back with the row moved without actually re-reading the data from the database? Thanks,
1
1930
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 "dt2", so the data will no longer left in "dt1". please help, many thanks.
2
4912
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 TextBoxes) works fine the first time round. I can see, edit and update the details from my form, then close the form. I then like to select and refill the datatable with a different record (new
14
3601
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 will have to same amount of records but might have different amount of columns. So I need the first record form table1 and table2 and table3 and table4 and table5 to be in record 1 in my merged array or table. Second record form table1 and...
10
3710
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 and then fill a few simple labels. **Assuming** that I wrote the function properly, how exactly can I write the page_load sub to read the data from the function? I've tried a few examples from a couple of books I have but can't seem to get a...
4
3514
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 rows are being read and inserted into the table. The problem is that one of the columns in the CSV contains the value of 1 thru 6 or C, BUT only the numbers seem to be read into the DataTable not the letter. I tried single quotes and double quotes...
6
2944
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) Constraint pk_table1 Primary Key,
0
8991
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4606
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2783
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.