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

Treeview drag doesn't display no. of item selected

1 Answer 111 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
SANJAY
Top achievements
Rank 1
SANJAY asked on 19 Sep 2012, 05:59 AM
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.

Thanks,

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 21 Sep 2012, 01:10 PM
Hello Sanjay,

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

C#
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;
    }
}

VB.NET
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.

Greetings,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Treeview
Asked by
SANJAY
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or