This is a migrated thread and some comments may be shown as answers.
IEditableObject, CancelEdit
3 Answers 9 Views
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 2
Marco asked on 29 Jan 2016, 10:53 AM

Hello,

Having a datasouce implementing IEditableObject. Is there a way with the gridview to call the CancelEdit on a row scope ?

I have no problem to validate a cell value and to cancel the change when it is not valid. But I have no idea how to do this on a row scope.

Something like the sliverlight GridView (first ESC cancel the cell editor, second ESC cancel the row changes)

http://demos.telerik.com/silverlight/#GridView/Commands

My business need is the following :

For a given day, I should record a list of time range object having two properties (StartTime, EndTime). When a Cell is validated, I check that the editor could be converted to a Timespan. When a row is validated I check that the StartTime and the EndTime are not null, that the StartTime is not bigger than the EndTime and to check that there is no range overlap with another Row.

Thanks for your support

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 29 Jan 2016, 12:20 PM
Hi Marco,

Thank you for writing.

To implement such functionality with the WinForms grid you can store the row values and use them when needed:
List<object> values = new List<object>();
 
private void RadGridView1_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
{
    if (!(e.CurrentRow is GridViewDataRowInfo))
    {
        return;
    }
    changes = 0;
    values.Clear();
    foreach (GridViewCellInfo item in e.CurrentRow.Cells)
    {
        values.Add(item.Value);
    }
}
private void RadButton1_Click(object sender, EventArgs e)
{
    this.CancelRowChange();
}
public void CancelRowChange()
{
    for (int i = 0; i < radGridView1.CurrentRow.Cells.Count; i++)
    {
        radGridView1.CurrentRow.Cells[i].Value = values[i];
    }
}
 
You can capture the second Escape press as well:
int changes = 0;
private void RadGridView1_CellValueChanged(object sender, GridViewCellEventArgs e)
{
    changes++;
}
 
private void RadGridView1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyData == Keys.Escape)
    {
        if (changes == 2)
        {
            this.CancelRowChange();
        }
    }
}

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
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
0
Marco
Top achievements
Rank 2
answered on 02 Feb 2016, 11:16 AM

Thanks for answering Dimitar

I had to add some stuff because of my hierarchical Grid but it's working.

Shouldn't we check that changes is greater than 0 in KeyDown handler ?

0
Dimitar
Telerik team
answered on 02 Feb 2016, 03:09 PM
Hello Marco,

Thank you for writing back.

Yes, of course, the changes variable will indicate the number of changed cells in the row.

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
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
Asked by
Marco
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Marco
Top achievements
Rank 2
Share this question
or