This is a migrated thread and some comments may be shown as answers.

updates to database failing for highlighted (current) row

3 Answers 50 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Barry
Top achievements
Rank 1
Barry asked on 05 Oct 2016, 10:19 PM

I have a winform with a radgridview with filtering enabled. The data source is a dataset. The purpose of the form is to make various global updates to a weight column in the database. So for example the user first sets a filter, for example on a specific zipcode, and say that there are 4 rows that meet that condition. Next to the grid I have a text box and a command button. The user inputs the package weight that is for the filtered zip and clicks a submit button. The code then applies the package weight to the filtered records - this works - and all the values for package weight get properly set and are shown in the grid. Then I have a 'save all' button - this is *almost working'.  Previously the code I had in the save button click was:

            this.tblDISTRIBUTIONACTIVITYBindingSource1.EndEdit();
           this.tmcprod1024DataSet1.AcceptChanges();
           nretval = this.tblDISTRIBUTIONACTIVITYTableAdapter1.Update(tmcprod1024DataSet1.tblDISTRIBUTIONACTIVITY);

And in this case, the backend data was never updated, no updates whatsoever.  However, I then read some online posts and realized that I needed to eliminate the "acceptchanges" line. After I eliminated that line things were *almost correct* but still not there yet. Now, taking the example above with 4 filtered records, when I click the save button, if say for example the third record is highlighted in the grid, then the three non-highlighted records get updated on the backend, but the highlighted record  doesn't get updated. Regardless of which row is highlighted at the time of clicking save, the data on the highlighted  row doesn't get updated.  Can someone please explain what is wrong and how I can fix this? Thanks.

The code that changes the weight value in the grid, upon clicking the command button, is as follows:

            foreach (var onerow in radGridView1.ChildRows)
            {
                double dnumber;
                dnumber = Convert.ToDouble(maskedTextBox2.Text);
           
                onerow.Cells["customerratethisorder"].Value = dnumber;

        }

 

 

 

3 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 07 Oct 2016, 09:51 AM
Hello David,

Thank you for writing.

It appears that the RowState of the underlying DataRowView is not updated. Please check the following documentation article handling a couple of scenarios of updating the database in a similar scenario: Updating the Database with ADO.Net.

Additionally, you may need to call the EndEdit method of the underlying IEditableObject instance:
void radGridView1_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    IEditableObject editbaleObject = e.Row.DataBoundItem as IEditableObject;
    if (editbaleObject != null)
    {
        editbaleObject.EndEdit();
    }
    DataRowView dataRowView = e.Row.DataBoundItem as DataRowView;
    if (dataRowView != null)
    {
        this.employeesTableAdapter.Update(dataRowView.Row);
    }
}
 
I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms. For more information check out this blog post and share your thoughts.
0
Barry
Top achievements
Rank 1
answered on 13 Oct 2016, 06:58 PM

Hello Hristo,  Thanks for your help. I got a similar reply from Dess and applied her recommended changes and it now works.

 

0
Hristo
Telerik team
answered on 14 Oct 2016, 01:07 PM
Hi David,

Thank you for writing.

I am glad that it is working well your actual project.

Please let me know if you need further assistance.

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Barry
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Barry
Top achievements
Rank 1
Share this question
or