Did you know that the ASPxTreeList has an editor form mode? Many of you probably did. Like the ASPxGridView this means you can edit a node in the tree list using a form for making changes to the data rather than plain old TextBoxes, in edit form mode you get controls that are generally more type friendly and an input layout that is a little more intuitive.
Did you know that the ASPxTreeList lets you define custom templates? It does. While the ASPxTreeList is pretty good at figuring out how to design and edit form and the column properties and style properties will let you manage the appearance of the ASPxTreeList in a lot of ways, you can define your own edit form. To do so click the Smart tags menu, click Edit templates, choose the EditForm template and design away.
But wait, how do you implement the equivalent of the Update and Cancel command? Ah! the easy answer is the ASPxTreeListTemplateReplacement . (That’s a mouthful. working on the book I wrote that about ten times.) Unfortunately, the ASpxTreeListTemplateReplacement control is not in the toolbox by default. You have to add it. The easy way to get the Update and Cancel commands in your ASPxTreeList template is to:
- Open the Toolbox in Visual Studio
- Expand the Developer Express Data tab
- Right-click to display the Toolbox context menu and click Choose Items
- On the .NET tab of the Choose Toolbox Items dialog scroll down until you see the ASPxTreeListTemplateReplacement control
- Check the box next to it and close the dialog
Once you have the ASPxTreeListTemplateReplacement control in the Toolbox use this control to create the Update and Cancel buttons as needed for ASPxTreeList templates. To configure the update button change the ASPxTreeListTemplateReplacement.ReplacementType to UpdateButton, and to configure the Cancel button change the other ASPxTreeListTemplateReplacement.ReplacementType to CancelButton. That’s all you need to do. With these controls no code is needed to invoke the update and cancel behaviors for the ASPxTreeList in edit mode.