CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2011

    Unhappy Programatically adding a row to a DataGridView that is bound to a datasource


    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" };

    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";

    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

    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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.