C# How to edit the data in Datagridview? C#

koala-london
koala-london used Ask the Experts™
on
I need help on how to edit the datagridview in C#. currently I can edit the data in datagridview but didn't save the data to the database.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Can you post your current code?
Of course it does not save automatically to database. We must make a "Save" button and when clicking on it, call the "Save function" that save reflexing data to database through DataGridViewRow.DataBoundItem, then call "Refresh function". That's what i'm doing till now when dealing with Windows form programming.
One more thing, any changes on your GridView will not affect data on your database, so you have to write functions to do that. For ex, here's your code in my last project (using the old SCSF)

        private void btnbDel_Click(object sender, EventArgs e)
        {
            if (gvList.SelectedRows != null && gvList.SelectedRows.Count > 0)
            {
                if (Util.ShowQuestionMessage("Are you sure to delete selected record(s) ?") == DialogResult.Yes)
                {
                    foreach (DataGridViewRow r in gvList.SelectedRows)
                    {
                        RentType data = (RentType)r.DataBoundItem;
                        _presenter.Delete(data);
                    }

                    _presenter.RefreshData();
                }
            }
        }
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Ayman AboualnourSoftware Developer

Commented:
How you retrieve your data (what is your DataSource for the grid) because I think there is a misunderstanding, the DataGridView is working in disconnected mode so the datata is not automatically updated like Access that working in a connected mode where the data is automatically updated after row modifications. the best way is to use a DataSet Table as a source for your data to easy retrieve & update these data.
Commented:
HI koala-london,

            Please check this links.

C# DataGridView Tutorial:

http://dotnetperls.com/datagridview-tutorial

http://dotnetperls.com/datagridview-tips

Edit and Delete multiple Data in DataGrid in ASP.NET:

http://www.codeproject.com/KB/aspnet/Edit_and_Delete_Data.aspx

Data Binding with Windows Forms 2.0: Programming Smart Client Data Applications with .NET:

http://www.codeproject.com/KB/books/PresentDataDataGridView.aspx

DataGridView..::.EditMode Property :

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.editmode.aspx

Author

Commented:
it works

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial