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

Make CurrentRow visible after cancelling changes.

4 Answers 52 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 17 May 2018, 09:13 AM

I have a master grid which can have 100's of rows. Only the top 20 rows are visible.

When I click on a row in the master grid, a second grid is populated with other editable data.

If I then click a different row on the master grid, test to see if we have a dirty record in the second grid.

If we do, then I pop up a confirm dialogue box.

On selecting discard, the changes in the second grid are removed, and on the master grid, I wish to make sure that the original row is visible.

So, I am using the CurrentRowChanging event on the master grid to pick up the change, setting the e = true, discarding the updated data in the second grid and finally setting the master grid CurrentRow to be the same as .CurrentRow.

All of this works fine.

My issue is that I want the CurrentRow to become visible within the master grid. Currently, if I have 50 records in the master grid, edit row 5, then discard after clicking row 45. I want row 5 to be visible in the master grid.

 

 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 May 2018, 11:09 AM
Hello, Paul,     

In order to scroll to a specific row that is not visible in the current view you can use the TableElement.ScrollToRow method. Thus, when you cancel the CurrentRowChanging event you can scroll to the current row to ensure that it is visible. Here is a sample code snippet: 

public RadForm1()
{
    InitializeComponent();
 
    this.radGridView1.CurrentRowChanging += radGridView1_CurrentRowChanging;
}
 
private void radGridView1_CurrentRowChanging(object sender, Telerik.WinControls.UI.CurrentRowChangingEventArgs e)
{
    if (e.NewRow.Index % 2 == 0)
    {
        e.Cancel = true;
        this.radGridView1.TableElement.ScrollToRow(e.CurrentRow);
    }
}

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

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paul
Top achievements
Rank 1
answered on 17 May 2018, 01:21 PM

I have tried this:

private void RgvQueue_CurrentRowChanging(object sender, CurrentRowChangingEventArgs e)
{
  
     DialogResult result;

            if (rbtnCommentsSave.Enabled == true)
            {
                if (e.NewRow.Index % 2 == 0)
                {
                    result = CustomMessageBox.ShowMessage("You have unsaved data" 
                                                    + Environment.NewLine + "are you sure you want to continue?",
                                                        "Warning Message", MessageBoxButtons.OK, MessageBoxIcon.Warning,
                                                            "Cancel_Changes", "Keep_Changes");
                    if (result == DialogResult.Cancel)
                    {
                        rbtnAddExpansionComment.Text = " ";
                        rcbxEmailComments.Checked = false;
                    }
                    else
                    {
                        //Cancel row change and keep edit
                        e.Cancel = true;
                        this.rgvQueue.TableElement.ScrollToRow(e.CurrentRow);
                    }
                }
            }
}

 

I am still getting the same result, whereby if I return DialogResult. .Cancel  = true; stops the event correctly, but the ScrollToRows is still not displaying the current row.

 

 

 

 

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 May 2018, 10:40 AM
Hello, Paul,     

Showing a message box and using the ScrollToRow method while you are changing the current row is a little bit tricky. It will result in double showing the message box. That is why I have prepared a sample project to demonstrate how to handle the MouseUp event, show the message box and scroll to the last current row if you reject the changing.

Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best. 

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

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Paul
Top achievements
Rank 1
answered on 21 May 2018, 07:33 AM
Thank you, this solved my problem 
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Paul
Top achievements
Rank 1
Share this question
or