This is a migrated thread and some comments may be shown as answers.

Make Dynamic Node template from code behind for the leaf nodes or option to drag (not remove) the node text onto some editor/area

1 Answer 93 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
kamii47
Top achievements
Rank 1
kamii47 asked on 05 Jul 2013, 06:07 AM
Hi guys.I am creating tree view from some of my class object dynamically.
What i need to do is drag(just drag not remove) the leaf node into the rich text editor text.



I have tried to create the nodetemplate but not succcessful( other wise just add the node template in the leaf node with label)
Following is the code of making the treeview node.

TreeView1.Nodes.Clear();

            DocumentTemaplateCompiledDto obj = DocumentTemaplateCompiledBll.GetInstance.GetDocumentTemaplateCompiledByTemplateId(Int32.Parse(ddlTemplates.SelectedValue));


if (obj.LstSections != null && obj.LstSections.Count > 0)
            {
                foreach (var objSection in obj.LstSections)
                {
                    var tNode = new RadTreeNode(objSection.SectionName);                  
 
                    if (obj.LstSimpleFields != null && obj.LstSimpleFields.Any(h => h.FkDocumentTemplateSectionId == objSection.DocumentTemplateSectionId))
                    {
                        var tNodeChildSimpleFields = new RadTreeNode("Simple_fields_Control");
 
                        foreach (var objSimplefield in obj.LstSimpleFields.FindAll(h => h.FkDocumentTemplateSectionId == objSection.DocumentTemplateSectionId))
                        {
                            var tNodeChildGridTextEntry = new RadTreeNode(objSimplefield.FieldName);
                            tNodeChildGridTextEntry.Nodes.Add(new RadTreeNode
                            {
                                Text = objSimplefield.FieldCode,//these are the leaf node
                                AllowEdit = true,//this I have done as a last possible option
                                AllowDrop = true,//this I have done as a last possible option
                                AllowDrag = true//this I have done as a last possible option
                            });
                            tNodeChildSimpleFields.Nodes.Add(tNodeChildGridTextEntry);
                        }
                        tNode.Nodes.Add(tNodeChildSimpleFields);
                    }
                    TreeView1.Nodes.Add(tNode);
                }
            }
             
            


<telerik:RadEditor ContentAreaMode="Div" runat="server" ID="RadEditor1" Height="515"
            Width="700" Visible="True">
            </telerik:RadEditor>


Please suggest me how can i achieve my desired reuslt.
Any help guys?

1 Answer, 1 is accepted

Sort by
0
kamii47
Top achievements
Rank 1
answered on 08 Jul 2013, 06:38 AM
I have myself solve the problem to some extent

I have made a class 

public class MyNodeTemplate : ITemplate
    {
        public string StrText { get; set; }
 
        public void InstantiateIn(Control container)
        {
            var txt = new TextBox();
            if (!String.IsNullOrEmpty(StrText))
            {
                txt.Width = new Unit(StrText.Length, UnitType.Em);
                txt.Text = StrText;
            }
            container.Controls.Add(txt);
        }
    }

And then with following code from code behind

var tNodeChildGridTextEntry = new RadTreeNode(objGrid.GridName);
                                var tGridFiledLeafNode = new RadTreeNode { Expanded = true };
 
                                var objtemplate = new MyNodeTemplate { StrText = objGrid.GridCode };
                                objtemplate.InstantiateIn(tGridFiledLeafNode);
                                tNodeChildGridTextEntry.Nodes.Add(tGridFiledLeafNode);
 
                                //tNodeChildGridTextEntry.Nodes.Add(new RadTreeNode
                                //{
                                //    Text = objGrid.GridCode,
                                //    AllowEdit = true,
                                //    AllowDrop = true,
                                //    AllowDrag = true
                                //});
                                tNodeChildGrid.Nodes.Add(tNodeChildGridTextEntry);

I were able to make my leaf node as text boxes.Problem is solve to quite extent that in text box I Ctr+C (copy )and then Psted on the text editor place easily.
One more problem is that if i try to drag the text from the textbox it drops to any external resource [like my file in notepad++, google searchbar, e.t.c]  easily but when i drag it to telerik text editor nothing happened.
When there is some text in label(outside treeview) and i drag it onto the text editor i were able to do it.
Strange behavior


   
Tags
TreeView
Asked by
kamii47
Top achievements
Rank 1
Answers by
kamii47
Top achievements
Rank 1
Share this question
or