How to copy the nodes of a Treeview to a Textbox

0

I need to copy the nodes of a TreeView to a TextBox in Visual Studio 2015 asp.net C #. But the AllowDrop or Enable DragAndDrop function does not appear in the TreeView properties. Any idea how I could do it? Thanks

    
asked by David García 01.12.2017 в 23:34
source

1 answer

0

The TreeView control does not include drag-and-drop functionality.

However, what you comment can be implemented easily using a client library like jQuery UI.

For this you must include references to the jQuery and jQuery UI libraries. And the code would be quite simple:

<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <script type="text/javascript">
        $(function() {
            $('#TreeView1 a').draggable({helper: 'clone'});
            $('#TextBox1').droppable({
                drop: function (event, ui) {
                    $(this).val(ui.draggable.text());
                }
            });
        });
    </script>
</head>

This code sets the anchors elements ( a ) contained in the element with id "TreeView1" (you should replace it with the Name of your TreeView) as "draggables" (elements that can be dragged).

Next, set the element with id "TextBox1" (you should replace it with the Name of your TextBox) as "droppable" (element to which other elements can be dragged). When an element is released (function drop ) it obtains the text of the element dragged and sets it as a value of the TextBox.

    
answered by 03.12.2017 в 21:51