BeforeDelete event is not being raised on UltraTree control when nodes are deleted. Is this a bug, am I doing something wrong or misunderstanding what this event represents?
To reproduce, place an UltraTree control and a button onto a new Form in a new Windows Forms project. Replace the designer code with this below. Press the button to delete a node and notice that the MessageBox does not appear. Am I missing a setting or something for this event to be enabled or is this a bug?
public partial class Form1 : Form
{
public
Form1()
InitializeComponent();
this.ultraTree1.BeforeDelete += new Infragistics.Win.UltraWinTree.BeforeNodeDeleteChangedEventHandler
(ultraTree1_BeforeDelete);
UltraTreeNode node = this
.ultraTree1.Nodes.Add();
node.Text =
"Parent";
node.Nodes.Add(
"c1", "Child1");
node.Nodes.Add("c2", "Child2");
}
void ultraTree1_BeforeDelete(object sender, Infragistics.Win.UltraWinTree.BeforeNodesDeletedEventArgs
e)
MessageBox.Show(string.Format("Deleting {0}", e.Nodes.Length.ToString()));
private void button1_Click(object sender, EventArgs e)
ultraTree1.Nodes[0].Nodes.RemoveAt(0);
pnewman,
The UltraTree's BeforeDelete event only fires when an UltraTreeNode is deleted via the UI; it does not fire when an UltraTreeNode is removed programatically.
~Kim~
Kim,
Thank you for the information. It's a shame the documentation doesn't say that!
I still need some way of detecting when nodes are being deleted from the UltraTree programatically. Do you (or anyone) have any suggestions on how this might be achieved?
Thanks.
Hi,
Firing events in response to programmatics changes is something of a gray area. Some controls do it and some dont. Some controls are inconsistent and fire the event for some operations and not others.
There's no really good rule of thumb for why this is. But the basic idea behind firing an event is to let you know that something occurred. When the user deletes a node, you have no way of knowing unless the control fires an event to tell you that is happened. But when you delete a node programmatically, you presumably know that you did it and therefore don't need an event to tell you so.
Soone way to handle this would be to create a method and call that method both from the event and from wheever else in your code you are deleting nodes.