Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > How to add New Column to existing DataTable in specific position.

Reply
Thread Tools

How to add New Column to existing DataTable in specific position.

 
 
GoodMorningSky
Guest
Posts: n/a
 
      10-05-2004
I want to add new DataColumn to existing DataTable object as first column
shown in the datagrid.
(like
DataColumn dc = new DataColumn("Target");
dc.DataType = typeof(string);
dc.DefaultValue = tbl.TableName;
tbl.Columns.Add(dc);
)
Whenever I add it, the column is shown at the end.
How can I add it as first column (or with index)?


 
Reply With Quote
 
 
 
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      10-05-2004
Does the order of the data columns really matter? You can determine the
order of the columns when you design the grid.

"GoodMorningSky" <(E-Mail Removed)> wrote in message
news:uxjS$(E-Mail Removed)...
>I want to add new DataColumn to existing DataTable object as first column
> shown in the datagrid.
> (like
> DataColumn dc = new DataColumn("Target");
> dc.DataType = typeof(string);
> dc.DefaultValue = tbl.TableName;
> tbl.Columns.Add(dc);
> )
> Whenever I add it, the column is shown at the end.
> How can I add it as first column (or with index)?
>
>


 
Reply With Quote
 
 
 
 
Alex Homer
Guest
Posts: n/a
 
      10-05-2004
DataGridColumnCollection.AddAt Method
http://msdn.microsoft.com/library/de...addattopic.asp


 
Reply With Quote
 
Ken Cox [Microsoft MVP]
Guest
Posts: n/a
 
      10-05-2004
Hmmm. That adds to the datagrid but he asked about the DataTable

"Alex Homer" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> DataGridColumnCollection.AddAt Method
> http://msdn.microsoft.com/library/de...addattopic.asp
>
>


 
Reply With Quote
 
Alex Homer
Guest
Posts: n/a
 
      10-06-2004
You mean you're supposed to read the question as well? <g>

I guess one way would be to build a new DataTable by adding the new column
first and then using the
DataColumnCollection.AddRange Method
to copy the others, but that seems hard work. Better to just specify the
columns in the required order in the control that displays the rows (which
is where I was going with the DataGrid...)

.... or change the query that fills the DataTable?

"Ken Cox [Microsoft MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hmmm. That adds to the datagrid but he asked about the DataTable
>
> "Alex Homer" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > DataGridColumnCollection.AddAt Method
> >

http://msdn.microsoft.com/library/de...addattopic.asp
> >
> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
asp.net vb existing datatable add row janetb ASP .Net 1 02-08-2010 02:50 PM
how to search/replace items in specific column of a datatable TB ASP .Net 2 02-26-2006 09:40 PM
How can I add a row from a typed datatable to another instance of that typed datatable? Ersin Gençtürk ASP .Net 1 10-06-2004 01:11 PM
Create a Datatable from a SQL datatable column shema? jg ASP .Net 1 08-17-2004 09:43 PM



Advertisments