質問

I'm having trouble adding a row to my datagridview for a redo button. I want to add the public string variable called DeletedFilmName to a new row in the first column (column is called "Films"), that's it. I've tried all sorts of things but can't seem to get this working, as simple as it seems.

Here's my error: "InvalidOperationException was unhandled. Rows cannot be programmatically added to the DataGridView's rows collection when the control is data-bound."

Private Sub Redo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Redo.Click
    FilmsDataGridView.Rows.Add(New Object() {DeletedFilmName})
End Sub

Any ideas? Thanks for your help in advance.

役に立ちましたか?

解決

The following code is an exmaple which explains how to add a new row to the DataGridView binds to a DataTable.

Code Snippet

        // DataGridView will generate a new row automatically
        SampleDataSet.CustomersRow newCustomersRow = sampleDataSet.Customers.NewCustomersRow();
        newCustomersRow.CustomerID = "1234-123";
        newCustomersRow.CompanyName = "Sample Works";
        sampleDataSet.Customers.Rows.Add(newCustomersRow);

Regards Ruban.J

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top