vendredi 17 avril 2015

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

I have a Datagridview,two buttons i.e AddEntry button and EditEntry button in a form.Whenever the form is loaded,data from an excel sheet will be loaded to the gridview.I dont have any problem in loading data from excel sheet to gridview.AddEntry button will redirect me to another form which has some textboxes to add entry. But,Whenever i'm trying to add a new entry to gridview by clicking AddEntry button,i'm facing an issue that "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;
}


Please help me out.Thanks in advance.


Aucun commentaire:

Enregistrer un commentaire