Treeview drag doesn't display no. of item selected

2 posts, 0 answers
    SANJAY avatar
    2 posts
    Member since:
    Jul 2012

    Posted 19 Sep 2012 Link to this post

    Hi All,

    I have treeview with drag and drop enabled and also set the "multiSelect" property to true to select multiple node while drag. I need to show no. of selected nodes to drag like in windows file system while doing drag and drop operation.

  2. Svett
    Svett avatar
    728 posts

    Posted 21 Sep 2012 Link to this post

    Hello Sanjay,

    You can use the PreviewDragHint event of RadTreeViewDragDropService to create a custom drag hint image in the following way:

    this.radTreeView1.TreeViewElement.DragDropService.PreviewDragHint += this.OnPreviewDragHint;

    private void OnPreviewDragHint(object sender, Telerik.WinControls.PreviewDragHintEventArgs e)
        int count = this.radTreeView1.SelectedNodes.Count;
        if (count > 1)
            Size size = new Size(50, 50);
            Bitmap bitmap = new Bitmap(size.Width, size.Height);
            using (Graphics g = Graphics.FromImage(bitmap))
                string countText = "Count: " + count;
                SizeF textSize = g.MeasureString(countText, this.Font);
                float x = (size.Width - textSize.Width) / 2;
                float y = (size.Height - textSize.Height) / 2;
                g.DrawString(countText, this.Font, Brushes.Black, x, y);
            e.UseDefaultHint = false;
            e.DragHint = bitmap;

    AddHandler radTreeView1.TreeViewElement.DragDropService.PreviewDragHint, AddressOf OnPreviewDragHint

    Private Sub OnPreviewDragHint(sender As Object, e As Telerik.WinControls.PreviewDragHintEventArgs)
        Dim count As Integer = Me.radTreeView1.SelectedNodes.Count
        If count > 1 Then
            Dim size As New Size(50, 50)
            Dim bitmap As New Bitmap(size.Width, size.Height)
            Using g As Graphics = Graphics.FromImage(bitmap)
                Dim countText As String = "Count: " + count
                Dim textSize As SizeF = g.MeasureString(countText, Me.Font)
                Dim x As Single = (size.Width - textSize.Width) / 2
                Dim y As Single = (size.Height - textSize.Height) / 2
                g.DrawString(countText, Me.Font, Brushes.Black, x, y)
            End Using
            e.UseDefaultHint = False
            e.DragHint = bitmap
        End If
    End Sub

    I hope this helps.

    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. DevCraft R3 2016 release webinar banner
Back to Top