-
January 25th, 2011, 11:22 AM
#1
Programatically adding a row to a DataGridView that is bound to a datasource
Hi!
I've been trying the whole evening to programatically add rows to my DataGridView but I can't seem to get it working I tried lots of differents ways but none of them seem to be working.
I get no errors, everything looks fine.
I have a WinForm, I added a DataGridView, bound a DataSource to it (table from a SQL 2008 connection).
The data shows up in it, everything is fine but I want to process the data before showing it, so I want to programatically add rows myself.
Here's what I tried so far:
string[] rowArray = new string[]{ "Test", "Test", "Test" };
dataGridView.Rows.Add(rowArray[0]);
-
dataGridView.Rows.Add();
int newRowIndex = dataGridView.RowCount - 1;
DataGridViewRow newRow = dataGridView.Rows[newRowIndex];
newRow.Cells["PurchaseOrderId"].Value = "Test";
newRow.Cells["SupplierId"].Value = "Test";
newRow.Cells["State"].Value = "Test";
-
DataRow newRow = purchaseOrders.NewRow(); // purchaseOrders = this.purchaseOrderManagerDataSet.PurchaseOrders
newRow["PurchaseOrderId"] = "Test";
newRow["SupplierId"] = "Test";
newRow["State"] = "Test";
dataGridView.Rows.Add(newRow);
None of them adds something to the DataGridView.
Any idea of what I'm doing wrong?
Thanks a lot!
-
April 8th, 2011, 06:24 AM
#2
Re: Programatically adding a row to a DataGridView that is bound to a datasource
Why not add the rows to the DataSource instead?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|