Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-13
3
Medium Priority
?
205 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

636 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