"Refresh" GridView After Pressing Cancel Button

5 posts, 1 answers
  1. Matthew
    Matthew avatar
    18 posts
    Member since:
    Oct 2014

    Posted 19 Nov 2015 Link to this post

     Hi,

     I have a gridview that is bound to a SQL Server DB table.  Users of the gridview can perform inline editing and save their changes using a save button.  The issue I am having is when a user makes changes to a row or rows and then presses a cancel button.  How do I reset these rows back to their initial values when a cancel button is clicked.  Is their a way to refresh or rebind the gridview?

     

     Thanks,

    Matthew

  2. Dess
    Admin
    Dess avatar
    1607 posts

    Posted 20 Nov 2015 Link to this post

    Hello Matthew,

    Thank you for writing.

    In order to refresh the entire grid, you can use the RadGridView.MasterTemplate.Refresh method. However, you can refresh a certain row by calling the InvalidateRow method for the affected GridViewRowInfo.

    I hope this information helps. Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Matthew
    Matthew avatar
    18 posts
    Member since:
    Oct 2014

    Posted 20 Nov 2015 in reply to Dess Link to this post

    Hi Dess,

     Thanks for your response.  I tried both the RadGridView.MasterTemplate.Refresh method and the InvalidateRow method and didn't have success with either one.

     

    Below is the code from my cancel button click event method:

     

    private void btnCancel_Click(object sender, EventArgs e)
    {
        btnCancel.Visible = false;
        btnSave.Visible = false;
        btnAdd.Visible = true;
        btnEdit.Visible = true;
     
        foreach (int x in updatedRows)
        {
            mainGrid.Rows[x].InvalidateRow();
        }
     
        updatedRows.Clear();
    }

     updatedRows is simply a list of the row indexes that have been modified.  If the user presses cancel, I want these modified rows to be invalidated and their values to revert back to what is stored in the DB.

     

    I've also attached a screenshot of the binding source that the grid datasource was set to.  I originally set this grid datasource using the 'Add project data source' wizard.  Again, this is a direct connection to a 'vendors' SQL Server DB table.  Am I missing something here? 

     

    Thanks,

    Matthew

     

     

     

     

  5. Matthew
    Matthew avatar
    18 posts
    Member since:
    Oct 2014

    Posted 20 Nov 2015 in reply to Dess Link to this post

    What ended up working was reassigning my gridview datasource like so:

     

    mainGrid.DataSource = vendorsTableAdapter.GetData();

     

    It would still be useful for myself (and probably others) to understand why using the InvalidateRow method didn't work as expected.  Any guidance you guys can offer would be wonderful.

     

    Kind Regards,

    Matthew

     

     

  6. Answer
    Dess
    Admin
    Dess avatar
    1607 posts

    Posted 25 Nov 2015 Link to this post

    Hello Matthew,

    Thank you for writing back.

    The provided explanation is greatly appreciated. When you edit a cell, this value is stored in the grid. However, the database is still not updated. Refreshing the row/ master template will invalidate the rows, but the cell values will not be reverted back as it is data information, not style. That is why it is necessary to set the DataSource property again as you have already found out. Thus, RadGridView will load the records from the database with the desired values.

    I hope this information helps. If you have any additional questions, please let me know.

    Regards,
    Dess
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready