Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2004, 05:32 AM
Authorized User
 
Join Date: Mar 2004
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default add column (C#)

hello
i have created DataTable ('dt') with 4 columns, now i want to add another column but i want this column to be the first column(its mean in index 0) and not in the end of this DataTable.
what can i do?
thanks
koby

 
Old July 21st, 2004, 10:58 AM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't recall it being possible to insert a column into the DataColumnCollection class. The only method available is Add and it always appends to the end. So to do what you asked, you must clear the existing collection. Add the new column then add back your original 4 columns. Something like
  dt.columns.copyto(myarray, 0);
  dt.columns.clear;
  dt.columns.add(mycolumn);
  dt.columns.addrange(myarray);






Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a new column into gridview? Bryan Stanley ASP.NET 2.0 Basics 0 September 12th, 2007 10:49 PM
Add 1 to next column deontae45 SQL Language 2 December 18th, 2006 01:42 PM
Add a Column to a DataGrid infernokodiak C# 7 January 18th, 2006 04:06 PM
Add Column in a View rekha_jsr Oracle 1 December 5th, 2004 04:58 AM
how to add new column to recordset?? huela Access VBA 0 October 13th, 2004 01:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.