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

Drag TextBlock from One User Control and Drop to other user control

2 Answers 46 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
HARSH
Top achievements
Rank 1
HARSH asked on 07 Jul 2010, 05:32 PM
Hi,

I want to drag 3 TextBlock from one user control and want to create textblock with same content in other user control.
So i am adding drag event is different textblocks of first user control and drop events in a grid of second user control.
First time when i am dropping an item it is working fine.
From next item onwards it is showing me arrow line which it has drawn while dropping first item.

My code is:
//UserControl2

 

 

private void OnDropInfo(object sender, DragDropEventArgs e)

 

{

 

 

if ( e.Options.Status==DragStatus.DropComplete)

 

{

 

 

 

 

//Code for custom processing
}
}


 

 

void OnDropQuery(object sender, DragDropQueryEventArgs e)

 

{

e.QueryResult =

 

true;

 

}

 //UserControl1

 

 

void OnDragInfo(object sender, DragDropEventArgs e)

 

{

}

 

 

 

protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)

 

{

 

 

TextBlock labelItem = e.Options.Source as TextBlock;

 

e.Options.Payload = labelItem;

 

 

ContentControl cue = new ContentControl();

 

 

 

StackPanel spanel = new StackPanel();

 

spanel.Children.Add(

 

new TextBlock(){Text =labelItem.Text});

 

cue.Content =spanel;

 

 

e.Options.DragCue = cue;

e.Options.ArrowCue =

 

RadDragAndDropManager.GenerateArrowCue();

 

e.QueryResult =

 

true;

 

 

}


Please provide me some sample code to fix this.

2 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 12 Jul 2010, 06:08 PM
Hello HARSH,

i noticed that you are generating an ArrowCue each time the OnDragQuery() fires, can you try generating it only when the status of the drag/drop operation is DragQuery instead, like so:
protected virtual void OnDragQuery(object sender, DragDropQueryEventArgs e)
{
    if (e.Options.Status == DragStatus.DragQuery)
    {
        TextBlock labelItem = e.Options.Source as TextBlock;
        e.Options.Payload = labelItem;
        ContentControl cue = new ContentControl();
        StackPanel spanel = new StackPanel();
        spanel.Children.Add(new TextBlock() { Text = labelItem.Text });
        cue.Content = spanel;
        e.Options.DragCue = cue;
        e.Options.ArrowCue = RadDragAndDropManager.GenerateArrowCue();
    }
    e.QueryResult = true;
}

Please give this approach a try and let me know if it works for you.

Best wishes,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
HARSH
Top achievements
Rank 1
answered on 20 Jul 2010, 04:23 PM
Thanks Tina.
It Works.
Tags
DragAndDrop
Asked by
HARSH
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
HARSH
Top achievements
Rank 1
Share this question
or