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
250
ValidateLabelEdit + StayInEditMode leads to e.OriginalText == null
posted

AIM: During rename of UltraTreeNode text

a)Press 'Enter' key: Remain in edit mode only (conditionally)

b)Press 'ESC'  key: Come out of edit mode and UltraTreeNode text  is not changed.  It remains original node text.

Problem:

Edit UltraTreeNode text, press 'ESC' Key: works fine. UltraTreeNode text is original text.

Edit UltraTreeNode text, press 'Enter' Key, press ESC key. UltraTreeNode text becomes new text.

Question 1: Why ESC key after (Enter key + StayInEditMode = true) makes UltraTreeNode as new text.?

Question 2: Why  (e.OriginalText == null)? in function  ValidateLabelEdit on pressing Enter Key 2nd time?

Looks like after going through (Enter key + StayInEditMode) route, the e.OriginalText looses its value and that could be reason for ESC key making UltraTreeNode text as new text.

Details:

- - - - - - - - - - - -

Case 1: (Works fine)

1) UltraTreeNode.BeginEdit(). Changed UltraTreeNode text.

2) Press 'Escape' key. UltraTreeNode text changes back to OriginalText.

 

Works fine.

 

Works fine.

Works fine.

 

Case 2: (Problem)

1) UltraTreeNode.BeginEdit(). Changed UltraTreeNode text.

 

2) User presses 'Enter' Key. In Function ValidateLabelEdit

e.StayInEditMode =

 

true;

 

 

is called. (User remains in edit mode only)

 

3) Press 'Escape' key. UltraTreeNode text changes to new text.

Case 3: (one observation)

 

 

 

1) UltraTreeNode.BeginEdit(). Changed UltraTreeNode text.

2) User presses 'Enter' Key. In Function ValidateLabelEdit

e.StayInEditMode =

 

true;

 

 

is called. (User remains in edit mode only)

 

e.OriginalText !=

 

null, it contains the original text. Good. 

 

 

3) User presses 'Enter' Key. In Function ValidateLabelEdit

e.StayInEditMode =

 

true;

 

 

is called. (User remains in edit mode only)

 

e.OriginalText =

 

null, it no more contains the original text. Observation.

This could be the reason that pressing ESC key after pressing Enter key had make the node text empty.

Source Code:

____________________________________________________

namespace UltraTree
{
    public partial class MyUltraTreeForm : Form
    {
        public MyUltraTreeForm()
        {
            InitializeComponent();
            this.MyultraTree.Override.UseEditor = Infragistics.Win.DefaultableBoolean.True;
            this.MyultraTree.ValidateLabelEdit += new Infragistics.Win.UltraWinTree.ValidateLabelEditEventHandler(this.MyultraTree_ValidateLabelEdit);
            this.MyultraTree.ExpandAll();
            this.MyultraTree.ActiveNode = this.MyultraTree.Nodes[0].Nodes[0];
        }

        private void EditNodeA_Click(object sender, EventArgs e)
        {
            this.MyultraTree.ActiveNode.BeginEdit();
        }

        private void MyultraTree_ValidateLabelEdit(object sender, Infragistics.Win.UltraWinTree.ValidateLabelEditEventArgs e)
        {
            EditorWithText editor = (EditorWithText)e.Node.EditorResolved;
            if (e.OriginalText == null)
            {
                // Error
                Infragistics.Win.UltraMessageBox.UltraMessageBoxManager.Show("e.OriginalText is empty");
            }

            e.StayInEditMode = true;
            //e.LabelEditText = // This I dont want to do.
        }
    }
}

 

 

__________________________________________________

 

 

Parents
  • 469350
    Offline posted

    Hi,

    Setting e.StayInEditMode keeps the node in edit mode, but it does not stop the new text from being committed to the node.To do that, you also need to set e.Cancel to true. This seems to give me the behavior you want:


            private void ultraTree1_ValidateLabelEdit(object sender, Infragistics.Win.UltraWinTree.ValidateLabelEditEventArgs e)
            {
                if (string.IsNullOrEmpty(e.LabelEditText))
                {
                    e.Cancel = true;
                    e.StayInEditMode = true;
                }
            }

Reply Children