updates to database failing for highlighted (current) row

4 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Jul 2014

    Posted 05 Oct Link to this post

    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;

            }

     

     

     

  2. Hristo
    Admin
    Hristo avatar
    714 posts

    Posted 07 Oct Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. David
    David avatar
    3 posts
    Member since:
    Jul 2014

    Posted 13 Oct in reply to Hristo Link to this post

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

     

  5. Hristo
    Admin
    Hristo avatar
    714 posts

    Posted 14 Oct Link to this post

    Hi David,

    Thank you for writing.

    I am glad that it is working well in 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.
Back to Top