Hi
I have bounded list on UltraTree, which is using Standard View Style. I have some code in Edit Label validation event, Where I try cancel the event try to keep label in edit mode.
I have this code in ValidateLabelEdit(object sender, ValidateLabelEditEvent)
if (!match.Success) { e.StayInEditMode = true; //e.Cancel = true; MessageBox.Show("Invalid ); return; }
It gets back the cursor to label edit only when e.Cancel = true is commented out, that is fine but now it does triggers the ValidateLabelEdit event again when I press any key.
Basically In stacktrace i see that, since this tree is bounded to collection, that has some subcription on keypress, so it end up in showing Invalid message twice.
How to get rid of onkeypress of bounded node event trigger ?
Hello Srinivasan,
The reason this happens is because the label of the node remains in edit mode and after the user presses a key that would cause it to exit edit mode (Mouser click out of it, Enter, Tab etc.) it would commit the label value of the node, causing the ValidateLabelEdit event to trigger once more until the user has provided a valid input.
As for your other question regarding the OnKeyPress, I’m not sure what you mean by this, however if you mean the KeyMappings of the UltraTree, they can be removed with the code below:
for (int i = this.ultraTree1.KeyActionMappings.Count - 1; i >= 0; i--)
{
if (this.ultraTree1.KeyActionMappings[i].KeyCode == Keys.Enter)
this.ultraTree1.KeyActionMappings.Remove(this.ultraTree1.KeyActionMappings[i]);
}
Please keep in mind that the even would still trigger if you click outside of the edit portion of the label.
Please let me know if you have any questions.
Regards, Ivan Kitanov
Thanks for your reply,
You are correct about the value getting committed because event is not canceled, but why do the ValidateLabelEdit event getting triggered when StayInEditMode is true and that makes cursor to be inside label edit control and any key is pressed on label edit? it happens for only first key pressed.
Actually , ideally e.Cancel should be set to true as below but when I do this this losses the focus from the tree node label which is still in edit mode.
if (!match.Success){e.StayInEditMode = true;e.Cancel = true;MessageBox.Show("Invalid );return;}
If I use this code without bounded list it works fine, but with bounded tree it looses focus. How can I get the focus back to tree node edit ?
thank you for checking
Could you elaborate more what do you mean by “any key is pressed on label edit”? Does it trigger the event when you try to type in a letter or a number, or does it trigger it when you press Tab, Enter etc. Is it possible to provide a detailed steps of how to achieve this behavior?
I tried the code you provided with both UltraTree with data bound to a list and with data generated from the designer and in both cases, there was no issue the event was triggering only when the label was exiting edit mode. This leads me to another question, which version of Infragistics Controls are you using?
Looking forward to hearing from you.
Hi,
Its very strange but these issues are happening only when you do tree.ExpanAll()
private void button2_Click(object sender, EventArgs e) { var mDuck = (MotherDuck) duckBindingSource.AddNew(); mDuck.Name = "Mary"; mDuck.DuckLings.Add(new Duck() { Name = "John Doe" }); mDuck.DuckLings.Add(new Duck() { Name = "John Mary" }); ultraTree1.Update(); }
private void button1_Click(object sender, EventArgs e) { ultraTree1.SelectedNodes[0].BeginEdit(); }
private void ultraTree1_ValidateLabelEdit(object sender, Infragistics.Win.UltraWinTree.ValidateLabelEditEventArgs e) { if(e.LabelEditText.Contains("1")) { e.StayInEditMode = true; //e.Cancel = true; MessageBox.Show("Failed"); } }
private void button3_Click(object sender, EventArgs e) { ultraTree1.ExpandAll(); }
Please try this code. There are two issues happening. If you dont do expand all and try to rename and type some name and change it back to orignal name then it does not change, it goes back to what I typed.
I tried to do it it in different way by invoking BeginEdit in AfterLabelEdit event in case of invalid name.. That also seem to fail to retain the focus on the tree control.
I will have to do lot of rework it this feature does not work. Please help
I have created a small sample trying to reproduce the described behavior. On my side everything works as expected and I am able to change the value of a node label, also when the value is incorrect an error message is given and the label is in edit mode until the user types a correct value. I also am unable to reproduce the behavior of renaming and reverting to the unsaved value.
Attached you will find my sample for your reference. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve, please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated, please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application, and attach it.
Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.
Thank you for your cooperation.
UltraTreeLabelEdit.zip