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

DragandDrop: From GridView To TreeView

3 Answers 60 Views
GridView
This is a migrated thread and some comments may be shown as answers.
miral shah
Top achievements
Rank 2
miral shah asked on 30 Oct 2009, 01:27 PM

Respected Sir,

Problem's Objective:Drag and Drop a row and also multiple row from RadGridview to RadTreeView item . 

Problem's Description : Well , i m having the RadgridView whose itemsource is binded with observableCollection and this GridView's itemsource  changes according to TreeView Item selected. Now i m trying to achieve Draging the gridview's row to TreeView Item but i m not getting the same 

I have viewed several post where by in Radgridview's xaml  Drag and Drop Functionality for its row is set as below:

 

<

 

 

gridView:RadGridView AutoGenerateColumns="True" x:Name="gridView"

 

 

 

 

UseAlternateRowStyle="False" dragDrop:RadDragAndDropManager.AllowDrop="True"

 

 

 

 

Grid.Column="1" Margin="30">

 

 

 

 

<gridView:RadGridView.RowStyle>
<Style TargetType="gridViewElements:GridViewRow">

 

 

 

 

<Setter Property="dragDrop:RadDragAndDropManager.AllowDrag" Value="True" />

 

 

 

 

</Style>

 

 

 

 

</gridView:RadGridView.RowStyle>

 

 

 

 

</gridView:RadGridView>

 

 

 

 

 
I want above thing in programatic way in code bind file in c#.

Also i m not to get the visibilty of Draging the row... i have done following things

 

 

RadDragAndDropManager.AddDragQueryHandler(this.gvEmail, OnDragQuery);

 

 

RadDragAndDropManager.AddDragInfoHandler(this.gvEmail, OnDragInfo);

 

 

EventManager.RegisterClassHandler(typeof(GridViewRow), RadDragAndDropManager.DropQueryEvent, new EventHandler<DragDropQueryEventArgs>(OnGridViewRowDropQuery));

 

 

EventManager.RegisterClassHandler(typeof(GridViewRow), RadDragAndDropManager.DropInfoEvent, new EventHandler<DragDropEventArgs>(OnGridViewRowDropInfo));

 

 


 

 

void gvEmail_RowLoaded(object sender, RowLoadedEventArgs e)

 

{

 

if (e.Row is GridViewHeaderRow || e.Row is GridViewNewRow || e.Row is GridViewFooterRow)

 

 

return;

 

 

var row = e.Row as GridViewRow;

 

 

this.InitializeRowDragAndDrop(row);

 

 

}

 

private void InitializeRowDragAndDrop(GridViewRow row)

 

{

 

if (row == null)

 

 

return;

 

row.SetValue(

RadDragAndDropManager.AllowDragProperty, true);

 

 

//row.SetValue(RadDragAndDropManager.AllowDropProperty, true);

 

}

 


As i m newbie to the Telerik please give your valuable suggestions.

Thanks in advance.

Miral Shah

3 Answers, 1 is accepted

Sort by
0
Miroslav
Telerik team
answered on 02 Nov 2009, 10:07 AM
Hello miral shah,

You can write this xaml in code as well. Setting the AllowDrop attached property is done like so:

// Make the GridView a drop target:
RadDragAndDropManager.SetAllowDrop(orderView, true);

Then you can register for the RowLoaded event of the GridView and set these properties to the Row there:

private void OnOrderViewRowLoaded(object sender, RowLoadedEventArgs e)
{
    var row = e.Row;
    RadDragAndDropManager.SetAllowDrop(row, true);
    RadDragAndDropManager.SetAllowDrag(row, true);
}

I have modifies an example we have to set these properties in code, it is attached to my reply.

Do you think this will work for you?

Regards,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
miral shah
Top achievements
Rank 2
answered on 02 Nov 2009, 02:20 PM
Dear Sir,

Above mention problem got solved by me.Thanks. Now i m having problem with RadTreeView as i have binded dynamically with class TreeViewFolder but at debug time i m getting parent node only even though i drag and drop to child node . Also i m trying to load image along with dragcue but i m not getting the same. image is only building with color of arrow. I want to have different image valid image when user drag items to valid treeview node or else invalid image for invalid treeview node.




Thanks in advance..


Miral Shah
0
Miroslav
Telerik team
answered on 06 Nov 2009, 09:01 AM
Hi Miral,

You say that
"i m getting parent node only even though i drag and drop to child node"

This may happen because the child nodes of the TreeView do not have their children collection initialized. This means that all collections in your view model (TreeViewFodler) should be initialized to an empty ObservableCollection, even though they may be empty. This is needed because the TreeView will not create collections by itself.

Yes, it is possible to change the image of the DragCue to indicate that a drop is possible or not.

Generally you can assign any object as a DrragCue, and then you can retrieve it from the e.Options.DragCue at any time. If you decide to use the built-in TreeViewDragCue class, you can set its IsDropPossible and it will change to indicate whether a drop is possible.

Does this help you? Could you give us more details about how you create your DragCue?

Best wishes,
Miroslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
miral shah
Top achievements
Rank 2
Answers by
Miroslav
Telerik team
miral shah
Top achievements
Rank 2
Share this question
or