Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
25
Edit node - does't accept change if new value is empty
posted

Is it possible to reverse changes made during edition of node if new value is empty or the same?

Something similar to AcceptChanges property in EditModeEnding for XamDataGrid.

  • 16495
    Verified Answer
    Offline posted

    Hello Monika,

    In order to prevent changes if the NewValue is empty or the same in XamDataTree you can use the NodeEnteringEditMode event to store the old value and NodeExitingEditMode event to access the new value. This way if it does not pass the check you can call the TextBox's Undo method:

    string oldValue = "";
    private void MyTree_NodeEnteringEditMode(object sender, BeginEditingNodeEventArgs e)
    {
        oldValue = (e.Node as XamDataTreeNode).Control.Content.ToString();
    }
    private void MyTree_NodeExitingEditMode(object sender, TreeExitEditingEventArgs e)
    {
        if (e.NewValue.ToString() == "" || e.NewValue.ToString() == oldValue)
            (e.Node.Control.Content as TextBox).Undo();
    }

    You can test this approach in the attached sample application.

    Please let me know if you need more information.

    Sincerely,
    Zhivko
    Associate Software Developer

    ReverseText.zip