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

Drag and Drop from a dynamic GridView

2 Answers 126 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Don Proctor
Top achievements
Rank 1
Don Proctor asked on 21 Apr 2010, 07:40 PM
Hi,

I have what might be an unusual requirement. I'm trying to tie together the RadTreeView and RadGridView so that the grid appears as a node in the tree. Seems like it should be possible, and I've gotten part way through. See the attachment for a visual. I have the grid appearing by setting the ItemContainerStyle of a RadTreeViewItem. See below for the code.

Now to the question. I want to be able to drag items from the grid to another component on the form (not shown in screenshot). How to do that? The examples I've seen so far rely on .cs code to register the event handlers

ie RadDragAndDropManager.AddDragInfoHandler(wishlistView, OnWishListDragInfo);

In my case, the grid is created on the fly by the Tree. So, I think I probably need to set up the event handling declaratively. Is that true, and can anyone help me with an example?

Thanks.



Here's the xaml for the tree

        <telerikNavigation:RadTreeView IsDragDropEnabled="False">
            <telerikNavigation:RadTreeViewItem Header="Groups"  ItemContainerStyle="{StaticResource TreeViewItemStyle}">
                <telerikNavigation:RadTreeViewItem/> <!-- placeholder item. This expands into a grid because of the ItemContainerStyle specified in the parent -->
            </telerikNavigation:RadTreeViewItem>
            <telerikNavigation:RadTreeViewItem Header="Elements">
                <telerikNavigation:RadTreeViewItem Header="Group1"/>
                <telerikNavigation:RadTreeViewItem Header="Group2"/>
                <telerikNavigation:RadTreeViewItem Header="Group3"/>
            </telerikNavigation:RadTreeViewItem>
            <telerikNavigation:RadTreeViewItem Header="Item3"/>
            <telerikNavigation:RadTreeViewItem Header="Item4"/>
            <telerikNavigation:RadTreeViewItem Header="Item6"/>
        </telerikNavigation:RadTreeView>

And here's the style set as the ItemContainerStyle
            <Style TargetType="telerikNavigation:RadTreeViewItem" x:Key="TreeViewItemStyle">
                <Setter Property="Template" Value="{StaticResource xxtemplate}" />
                <Setter Property="IsExpanded" Value="True"></Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <StackPanel HorizontalAlignment="Center" Margin="4,6"
                                    Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

2 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 22 Apr 2010, 01:30 PM
Hi Don Proctor,

RadDragAndDrop manager cannot be attached from XAML. However there several option to get the desired functionality:

 - Add Load handler of the grid in the XAML and attach to the dragdrop handlers from the code behind:
XAML:
Loaded="RadGridView_Loaded"


Code-behind:
private void RadGridView_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
    RadDragAndDropManager.AddDragQueryHandler(sender as DependencyObject, OnDragInfo);
    RadDragAndDropManager.AddDragInfoHandler(sender as DependencyObject, OnDragInfo);
}

- Create behavior that inherits from Behavior<T> to encapsulate the logic there
Behavior:
public class DragDropBehaviour:Behavior<FrameworkElement>
{
    protected override void OnAttached()
    {
        base.OnAttached();
        this.AssociatedObject.Loaded += new RoutedEventHandler(AssociatedObject_Loaded);
    }
 
    void AssociatedObject_Loaded(object sender, RoutedEventArgs e)
    {
        RadDragAndDropManager.AddDragQueryHandler(sender as DependencyObject, OnDragInfo);
        RadDragAndDropManager.AddDragInfoHandler(sender as DependencyObject, OnDragInfo);
    }
 
    internal void OnDragInfo(object sender, DragDropEventArgs e)
    {
 
    }
 
    internal void OnDragQuery(object sender, DragDropQueryEventArgs e)
    {
 
    }
}

XAML:
<i:Interaction.Behaviors>
     <local:DragDropBehaviour/>
</i:Interaction.Behaviors>

Please let me know if this works for you.

Best wishes,
Tsvyatko
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
Don Proctor
Top achievements
Rank 1
answered on 22 Apr 2010, 05:39 PM
Thanks Tsvyatko. Option #1 did just what I needed. I hadn't known about behaviors before either, so now I have a new technique.

Don
Tags
GridView
Asked by
Don Proctor
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Don Proctor
Top achievements
Rank 1
Share this question
or