Solved

How do I insert a column into a datagrid at position 0

Posted on 2004-10-13
3
203 Views
Last Modified: 2010-04-15
Hello all experts. I am populating a datagrid from a dataset. Afterwards I want to be able to insert a new column at positon zero. I am not using sql or any database. My grid data is all hardcode. Any help would be much appreciated.  
0
Comment
Question by:zstafa
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
tomasX2 earned 500 total points
ID: 12304162
just adding a column to the dataset should show up in the datagrid.
you want to show the column as the first column ( at position zero );

I would create a new dataset and add the column you want to add and then copy the others... then merge.

                  DataSet newDS = new DataSet();                  
                  newDS.Tables.Add(new DataTable(ds.Tables[0].TableName));
                  newDS.Tables[0].Columns.Add(new DataColumn("MyFirstColumn",typeof(string)));                  
                  for( int i = 0; i < ds.Tables[0].Columns.Count;i++)
                  {
                        newDS.Tables[0].Columns.Add(new DataColumn(ds.Tables[0].Columns[i].ColumnName, ds.Tables[0].Columns[i].DataType ));
                  }                  
                  newDS.Merge(ds);
                  dataGrid1.DataSource = newDS.Tables[0];





0
 
LVL 3

Author Comment

by:zstafa
ID: 12304192
thanks alot. I just copy and pasted the code and it works.
0
 
LVL 5

Expert Comment

by:tomasX2
ID: 12304198
Glad to help... good luck
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question