473,383 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Adding data to an existing gridview

17
I am trying to add data to an existing gridview, the gridview already has defined columns and I need to add data to these columns.

However when I use gridview.datasource, it just adds new columns to the gridview. It is properly not that hard to do this, but I have been hammering my head on this problem for the last three days and I haven’t been able to find any help on Google.

I have added the code I have already made and it works ok, it just adds new columns instead of putting the data in the existing columns.

Expand|Select|Wrap|Line Numbers
  1. private void GridViewFunktion()
  2.         {
  3.  
  4.             DataColumn colOrigName = new DataColumn("Original_Name");
  5.             DataColumn colNr = new DataColumn("Nr");
  6.             DataColumn colSystem_Hop = new DataColumn("System_Hop");
  7.             DataColumn colType = new DataColumn("Type");
  8.  
  9.  
  10.             myTable.Columns.Add(colOrigName);
  11.             myTable.Columns.Add(colNr);
  12.             myTable.Columns.Add(colSystem_Hop);
  13.             myTable.Columns.Add(colType);
  14.  
  15.             varStringedt = OtherFunktions.VARSTRINGEDT;
  16.  
  17.             for (int i = 0; i < varStringedt.Length; i++)
  18.             {
  19.                 DataRow myRow;
  20.                 myRow = myTable.NewRow();
  21.                 myRow["Original_Name"] = varStringedt[i];
  22.  
  23.  
  24.                 myTable.Rows.Add(myRow);
  25.             }
  26.  
  27.             ReMk1_SE_dataGridView.DataSource = myTable;
  28.         }
  29.  
Aug 30 '09 #1
1 6476
GaryTexmo
1,501 Expert 1GB
Just because two DataColumn objects have the same text name doesn't mean they're the same object. You're actually creating 3 brand new columns and putting them into myTable, which you then hook to your DataGridViewobject.

Also, if you call the above function more than once you're actually going to get more copies of your columns, since you're creating new DataColumn objects every single time.

I'd suggest having the columns be completely defined by the DataTable and have DataGridView empty... or build the columns for the DataTable based on what's in the DataGridView, then clear the DataGridView columns before you set it's DataSource

Does that make any sense or help you at all? I changed my thought process a few times in there so I realize I may be rambling a bit.
Aug 31 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Raj | last post by:
Hi, I am trying to add some more information to the table which already has a lot a data (like 2-3000 records). The new information may be adding 2-3 new columns worth. Now my questions are:...
4
by: Hans Merkl | last post by:
Hi, Is there a way to show the column headers of a GridView control even if there is no data? The only thing I see is the EmptyDataTemplate but I would also like to display the column headers. ...
0
by: AboutJAV | last post by:
I created a crystal report with the report.rpt reportdata.xsd I created the a new dataset with the reportdata myreportdata = new reportdata(); That automatically created a new dataset...
1
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a...
13
by: Tomasz Jastrzebski | last post by:
Helo All, The problem: GridView control does not render at all (header/footer) when the data source is empty. I have seen a similar question posted already, but I just can not believe there is...
2
by: Wayne Deleer | last post by:
Hi All, I'm currently working on a project, and I've come to a part where I want to add data to a GridView. BUT, I want to do it programmatically, with alot of control over everything. In my...
0
by: ganesh22 | last post by:
Hi... Iam using GridView in asp.net(2.0) .My requirement is user can add,update,delete in gridview I written the code for add & update but can u help adding rows in grid view My code: ...
2
by: Kbalz | last post by:
I have a user control that has a gridview in it. I am dynamically setting up its datasource and columns based on an XML file. I have everything done except adding columns to the gridview, so that...
3
by: =?Utf-8?B?V2FubmFiZQ==?= | last post by:
I have a gridview that uses a sqldatasource. The rows of the gridview are editable. When the gridview is in edit mode, one of the columns is a dropdown. In testing the editing, I deleted the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.