ListView DragDrop (and other questions)

17 posts, 0 answers
  1. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 23 May 2013 Link to this post

    I'm having trouble implementing DragDrop to sequence the ListViewDataItems.  I've seen the forum entry from 2011 about enabling DragDrop and I voted for that feature.  I see the DragDrop event in ListView but it doesn't seem to fire.  Is this feature coming soon or am I failing to implement it correctly?

    The attached picture should help clarify this.  I also want to:
    2. Hide borders on ListViews.
    3. Use some type of panel (FlowLayoutPanel or Rad anything) where I can prevent a horizontal scrollbar from appearing but show the vertical scrollbar.
    4. Put some kind of label above the ListView that implements the current theme (backcolor, backcolor2, backcolor3, backcolor4) like RadButton or the text area on the ToolWindow.
    5. Control the location of text (and Images) on the ListViewDataItem so I can move it (them) to the right some x pixels.


    Thank you,
    Gary
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 28 May 2013 Link to this post

    Hi Gary,

    Thank you for writing.

    1. There were some issues in the implementation of the drag drop operations of RadListView which we have addressed for our upcoming release. The fixes allow out of the box drag drop between two RadListViews which will be useful in your setup. Our next release is planned for the middle of the next month (June 2013). 

    2. You can remove the border of the list view using the following line of code:
    this.radListView1.ListViewElement.DrawBorder = false;

    3, 4. For your case you might like the look of RadPageView which you can place inside the tool window. It will allow you to avoid the vertical scroll bar. You can get a better idea of how the page view works in its different view modes from our demo application that is installed with the controls. Navigate to PageView >> View Modes. Another option would be to use one list view with two groups inside it and move items between the groups.

    5. You can use the VisualItemFormatting event to change the padding of the list view items:
    this.radListView1.VisualItemFormatting += radListView1_VisualItemFormatting;
     
    private void radListView1_VisualItemFormatting(object sender, ListViewVisualItemEventArgs e)
    {
        e.VisualItem.Padding = new Padding(10, 0, 0, 0);
    }

    I hope this will be useful. Should you have further questions, I would be glad to help.

    Regards,
    Ivan Petrov
    Telerik
    RadChart for WinForms is obsolete. Now what?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 31 May 2013 Link to this post

    For a ListView with ViewType = ListView, is there a way to sort the ListViewDataItems by their text?  (If the answer is myListView.Items.OrderBy<>, how do I code that?)
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 05 Jun 2013 Link to this post

    Hi Gary,

    Thank you for writing back.

    RadListView has a built-in mechanism for sorting the data it is displaying. In your case you will have to use the programmatic approach by adding SortDescriptor(s) to the SortDescriptors property of RadListView.

    I hope this helps. Do not hesitate to write back with further questions.

    Regards,
    Ivan Petrov
    Telerik
    RadChart for WinForms is obsolete. Now what?
  6. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 05 Jun 2013 Link to this post

    Ivan,
    It must be right in front of my face and I just don't see it.  I have this ListView on a PageViewPage on a PageView on a ToolWindow in a RadDock on my user control.  If I read this correctly, I should just add this code:

    SortDescriptor sort = new SortDescriptor("Available", ListSortDirection.Ascending);
    lvAvailable.EnableSorting = true;
    lvAvailable.EnableColumnSort = true;  
    lvAvailable.SortDescriptors.Add(sort);

    My ListView isn't sorting according to the text assigned to the ListViewDataItems.  I suspect that I'm not assigning the correct value to the text of the sort descriptor.  Here's the designer code for the ListView.

    // 
    // lvAvailable
    // 
    this.lvAvailable.AllowEdit = false;
    this.lvAvailable.AllowRemove = false;
    listViewDetailColumn1.HeaderText = "Available";
    this.lvAvailable.Columns.AddRange(new Telerik.WinControls.UI.ListViewDetailColumn[] {
    listViewDetailColumn1});
    this.lvAvailable.GroupItemSize = new System.Drawing.Size(120, 20);
    this.lvAvailable.HorizontalScrollState = Telerik.WinControls.UI.ScrollState.AlwaysHide;
    this.lvAvailable.ItemSize = new System.Drawing.Size(120, 20);
    this.lvAvailable.Location = new System.Drawing.Point(0, 0);
    this.lvAvailable.Margin = new System.Windows.Forms.Padding(0);
    this.lvAvailable.Name = "lvAvailable";
    this.lvAvailable.SelectLastAddedItem = false;
    this.lvAvailable.ShowColumnHeaders = false;
    this.lvAvailable.Size = new System.Drawing.Size(160, 132);
    this.lvAvailable.TabIndex = 2;
    this.lvAvailable.VerticalScrollState = Telerik.WinControls.UI.ScrollState.AlwaysHide;

    Thank you,
    Gary
  7. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 10 Jun 2013 Link to this post

    Hello Gary,

    Thank you for writing back.

    Looking at your code I cannot see anything incorrect. I tried to reproduce the issue you have described, but I was unable to do so. I have attached the project I tested the case with. If this does not represent your scenario, I would kindly ask you to modify it so it would reproduce your setup and the issue.

    Looking forward to your reply.

    Regards,
    Ivan Petrov
    Telerik
    RadChart for WinForms is obsolete. Now what?
  8. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 14 Jun 2013 Link to this post

    I installed Version 2013.2.612.40.  So back to drag/drop working out of the box.  I understand this feature is supposed to be part of this latest release.

    My ListView is set with ViewType = ListView, AllowDragDrop = True.  I'm adding ListViewDataItems to it and I'm handling the DragDrop event.  Is there anything else needed for...
    private void radListView1_DragDrop(object sender, DragEventArgs e)
     {
         //code here
     }
    the event to fire?  So far, I'm not seeing that event handler execute.

    Thank you,
    Gary
  9. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 19 Jun 2013 Link to this post

    Hello Gary,

    What you need to do is to use the control in unbound mode and set the AllowDragDrop properties to true. Attached you can find a sample project.

    I hope this helps.
     

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
  10. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 19 Jun 2013 Link to this post

    Thank you, Stefan.  But I think we're not talking about the same thing.  That example has two ListViews and demonstrates that I can drag and drop from either to the other.

    What I am trying to do involves only one ListView.  I can drag and drop ListVIewDataItems to reorder them on the ONE ListView just fine.  But the DragDrop event is not being handled.  Is handling the event being fixed?

    Thank you,
    Gary
  11. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 24 Jun 2013 Link to this post

    Hello,

    Gary, RadListView uses RadDragDropService for drag and drop operations, hence the standard drag drop event is not fire. To handle the drag drop events of this service, here is how to access it:
    radListView1.ListViewElement.DragDropService
     
    //for example:
    radListView1.ListViewElement.DragDropService.PreviewDragDrop += DragDropService_PreviewDragDrop;

    I hope this is what you needed.
     

    Regards,
    Stefan
    Telerik
    RadChart for WinForms is obsolete. Now what?
  12. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 24 Jun 2013 Link to this post

    Thank you, Setfan.  I think I can make PreviewDragDrop work for this situation.  Since the DragDropService didn't show me any event that fires after a DragDrop occurs, I combined PreviewDrageDrop and MouseMove to get what I want.

    private void DragDropService_PreviewDragDrop(object sender, RadDropEventArgs e)
    {
        //ResetPanel();
        lvInUse.MouseMove += new MouseEventHandler(lvInUse_MouseMove);
    }
    void lvInUse_MouseMove(object sender, MouseEventArgs e)
    {
        lvInUse.MouseMove -= new MouseEventHandler(lvInUse_MouseMove);
        ResetPanel();
    }

    Unless there is a better choice, I'm pretty sure that it would be impossible for the user to perform consecutive dragdrops on the ListView without a mousemove between them.  The ResetPanel() method is setting the indices of controls on a FlowLayoutPanel based upon the sequence of the ListViewDataItems.  So I need that method to execute after the dragdrop completes.  If there is a better way to handle that than what I did here I would be happy to hear about it.
  13. Dan
    Dan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 25 Jun 2013 Link to this post

    Hi Gary,

    It sounds like I'm trying to implement something very similar to you and I struck across this thread while trying to solve the same problem.

    The DragDropService.Stopped event is firing for me after letting go of an item (i.e.: DragDrop "end") within the same ListView.  That event just has an EventArgs parameter but you can pick up the SelectedItems collection off the ListView or just scan the ListView and figure out the new sequence for them items.  This works for MultiSelect, too.

    What I'm trying to do is provide reordering of items within a ListView, but also allow the user to DragDrop an item from the ListView over to an adjacent TreeView.  By calling ListView.DoDragDrop(selected items, DragDropEffects.Move) in the DragDropService.Started event, the form seems to understand that a DragDrop procedure is underway, and the DragDrop event on the TreeView control fires when I let go of the item over the TreeView. 

    So far all of that is working at the same time...

    Thanks,
    Dan
  14. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 25 Jun 2013 Link to this post

    Hi Dan,

    Thanks for that information.  I did have great results with a TreeView and the DragDrop event in another situation.  DragDrop works in that control.

    In your puzzle, would the TreeView DragDrop event still work if you didn't call ListView.DoDragDrop(...) in the DragDropService.Started event?  This question is from my curiosity; it doesn't impact what I'm trying to do with my current project.

    Thank you,
    Gary
  15. Dan
    Dan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 26 Jun 2013 Link to this post

    Hi Gary,

    No, the TreeView's DragDrop event doesn't fire if I haven't made the DoDragDrop() call in the DragDropService.Started event, and I'm guessing that has something to do with the underlying WinForms logic that's involved with drag and drop operations.

    As another side-note, setting AllowDragDrop = true on the TreeView doesn't mess up the dropping of items from the ListView onto the TreeView.  The same re-ordering approach of binding to the TreeView's DragDropService.Stopped event for the built-in drag & drop within the same control appears to work; I can check the SelectedNode's Parent property to determine where the node has been re-ordered to, just like with the ListVIew.

    Thanks,
    Dan
  16. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 27 Jun 2013 Link to this post

    Hi guys,

    I can see you managed to find the answer to your question Gary, thanks to Dan's post.

    @Dan - your Telerik Points have been updated for the community effort.

    Please let us know if you have any other questions or if there is something pending I am omitting.
     

    Regards,
    Stefan
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  17. Doug
    Doug avatar
    50 posts
    Member since:
    Jul 2012

    Posted 01 Jul 2013 Link to this post

    Dan, your comment about the Stopped event finally registered and I understand how your answer provided the solution I was looking for.  I just now changed my code to use that event.  Thanks again.

    Gary
  18. Dan
    Dan avatar
    3 posts
    Member since:
    Jul 2010

    Posted 04 Jul 2013 Link to this post

    No problem, Gary!  I'm glad you got it working! :-)

    And thanks, Stefan!

    Dan
Back to Top
UI for WinForms is Visual Studio 2017 Ready