Custom TreeNodes and TreeNodeCollectionEditorDialog

Last post 01-24-2006 8:09 AM by srillaert. 0 replies.

Sort Posts:

  • Custom TreeNodes and TreeNodeCollectionEditorDialog

    01-24-2006, 8:09 AM
    • Member
      75 point Member
    • srillaert
    • Member since 11-15-2005, 1:41 PM
    • Belgium, EU
    • Posts 15
    Hi everyone,

    I have custom TreeView inheriting from the standard Treeview (let's call it CustomTreeView) and a custom TreeNode class inheriting from, you guessed it, TreeNode (let's call it CustomTreeNode). So far, so good. Developers can add and remove CustomTreeNode objects from the Nodes collection of the CustomTreeView programmatically and in the xml markup. So the following sample works just fine :

    <ny:CustomTreeView ID="TreeView1" runat="server" ExpandDepth="0" OnTreeNodePopulate="TreeView1_TreeNodePopulate">
        <Nodes>
            <ny:CustomTreeNode value="Root" Text="Root" NodeStyle-Height="20" NodeStyle-ForeColor="DeepSkyBlue" NodeStyle-Font-Underline="true">
                <ny:CustomTreeNode value="Alpha" Text="Alpha">
                    <ny:CustomTreeNode Value="Child1" Text="Child1" />
                    <ny:CustomTreeNode Value="Child2" Text="Child2" />
                </ny:CustomTreeNode>
                <ny:CustomTreeNode value="Beta" Text="Beta" PopulateOnDemand="True"/>
                <ny:CustomTreeNode value="Gamma" Text="Gamma"/>
            </ny:CustomTreeNode>
        </Nodes>
    </ny:CustomTreeView>

    The problem is, when a developer uses the TreeView Node Editor (the UITypeEditor of the Nodes collection, opened by clicking on the '...'-button in the properties window or by clicking on 'Edit TreeNodes' in the CustomTreeView tasks), it opens a dialog that :

    - only allows the properties inherited from the base class TreeNode to be edited
    - only allows base TreeNodes to be added to the tree, so no possibility to add CustomTreeNodes
    - and last (and worst :)) when the user finally persist the changes (by clicking OK in the TreeView Node Editor) all the markup of the CustomTreeNodes is gone, so the above sample becomes :

    <ny:CustomTreeView ID="TreeView1" runat="server" ExpandDepth="0" OnTreeNodePopulate="TreeView1_TreeNodePopulate">
        <Nodes>
            <asp:TreeNode value="Root" Text="Root">
                <asp:TreeNode value="Alpha" Text="Alpha">
                    <asp:TreeNode Value="Child1" Text="Child1" />
                    <asp:TreeNode Value="Child2" Text="Child2" />
                </asp:TreeNode>
                <asp:TreeNode value="Beta" Text="Beta" PopulateOnDemand="True"/>
                <asp:TreeNode value="Gamma" Text="Gamma"/>
            </asp:TreeNode>
        </Nodes>
    </ny:CustomTreeView>

    It seems that the TreeView Node Editor is a System.Web.UI.Design.WebControls.TreeNodeCollectionEditorDialog but this is an internal sealed class. So one cannot change this behavior by subclassing from this class and changing the UITypeEditor on the Nodes collection so that it uses this 'CustomTreeNodeCollectionEditorDialog'.

    Is there any other solution that doesn't involve creating a totally new EditorDialog ?
    Stefaan Rillaert

    My Blog
Page 1 of 1 (1 items)