Programatically adding a row to a DataGridView that is bound to a datasource
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Programatically adding a row to a DataGridView that is bound to a datasource

  1. #1
    Join Date
    Jan 2011
    Posts
    1

    Unhappy 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!

  2. #2
    Join Date
    Mar 2011
    Location
    London
    Posts
    54

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center