IEditableObject, CancelEdit

4 posts, 0 answers
  1. Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 29 Jan Link to this post

    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

     

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 29 Jan Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Marco
    Marco avatar
    87 posts
    Member since:
    Apr 2011

    Posted 02 Feb in reply to Dimitar Link to this post

    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 ?

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 02 Feb Link to this post

    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
Back to Top