コード例 #1
0
        /// <summary>
        /// Returns a string containing the full paths of the specified items.
        /// </summary>
        /// <param name="toolboxControl">The <see cref="TreeListBox"/> control.</param>
        /// <param name="items">The items to examine.</param>
        /// <returns>A string containing the full paths of the specified items.</returns>
        private static string JoinItemFullPaths(TreeListBox toolboxControl, IEnumerable <object> items)
        {
            var fullPaths = new StringBuilder();

            foreach (var item in items)
            {
                fullPaths.Append(toolboxControl.GetFullPath(item)).Append('\n');
            }
            return(fullPaths.ToString().TrimEnd());
        }
コード例 #2
0
        /////////////////////////////////////////////////////////////////////////////////////////////////////
        // PUBLIC PROCEDURES
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a <see cref="IDataObject"/> based on the specified items.
        /// </summary>
        /// <param name="sourceControl">The source control that contains the items.</param>
        /// <param name="dataObject">The <see cref="IDataObject"/> to initialize.</param>
        /// <param name="items">The items to examine.</param>
        /// <returns>The <see cref="DragDropEffects"/> that specifies the allowed drag/drop effects for the <see cref="IDataObject"/>.</returns>
        /// <remarks>
        /// The default implementation of this method simply return <c>DragDropEffects.None</c>.
        /// Override this method to initialize the <see cref="IDataObject"/> with text and/or other data formats
        /// (such as <see cref="TreeListBox.ItemDataFormat"/> for supporting drag/drop),
        /// and to return an appropriate <c>DragDropEffects</c> result.
        /// </remarks>
        public override DragDropEffects InitializeDataObject(TreeListBox sourceControl, IDataObject dataObject, IEnumerable <object> items)
        {
            if (sourceControl == null)
            {
                throw new ArgumentNullException("sourceControl");
            }
            if (dataObject == null)
            {
                throw new ArgumentNullException("dataObject");
            }
            if (items == null)
            {
                throw new ArgumentNullException("items");
            }

            // Store the full paths to items in case we drop on the tree itself...
            //   Each item needs to have a unique path, which comes from adapter GetPath() calls
            var fullPaths = new StringBuilder();

            foreach (var item in items)
            {
                fullPaths.AppendLine(sourceControl.GetFullPath(item));
            }
            if (fullPaths.Length > 0)
            {
                dataObject.SetData(TreeListBox.ItemDataFormat, fullPaths.ToString());
            }

            // If there is one item, store its text so that it can be dropped elsewhere
            if (items.Count() == 1)
            {
                var viewModel = items.First() as TreeNodeModel;
                if (viewModel != null)
                {
                    dataObject.SetData(DataFormats.Text, viewModel.Name);
                }
            }

            return(DragDropEffects.Move);
        }