lundi 20 avril 2015

C# WinForms: Adding row to a DataGridView which is Data bound

I have a Datagridview containing two buttons, an AddEntry button and an EditEntry button in a form. Whenever the form is loaded, data from an excel sheet will be loaded to the gridview.

I don't have any problem loading data from excel sheet to gridview. AddEntry button will redirect me to another form which has some textboxes to add entry.

However, when I try to add a new entry to the gridview by clicking the AddEntry button, I get this error: "ROWS CANNOT BE PROGRAMMATICALLY ADDED TO THE ROW COLLECTION WHICH IS CONTROL BOUND/DATA BOUND".

Here is my code-behind AddEntry Button:

 private void AddEntry_Click(object sender,eventargs e)
 {
     gridview.Rows.Add(_sno.Text,_date.Text,_category.Text);
 }

Constructor in the form which has textboxes to add data:

DataGridView gridview;
public FinanceEntries_Open(DataGridView _grid,string filename)
{
    InitializeComponent();
    label2.Text = filename;
    gridview = _grid;
}

Aucun commentaire:

Enregistrer un commentaire