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

ListView DragDrop (and other questions)

16 Answers 329 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 23 May 2013, 09:34 PM
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

16 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 28 May 2013, 12:00 PM
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?
0
Doug
Top achievements
Rank 1
answered on 31 May 2013, 05:56 PM
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?)
0
Ivan Petrov
Telerik team
answered on 05 Jun 2013, 12:13 PM
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?
0
Doug
Top achievements
Rank 1
answered on 05 Jun 2013, 10:12 PM
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
0
Ivan Petrov
Telerik team
answered on 10 Jun 2013, 06:50 PM
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?
0
Doug
Top achievements
Rank 1
answered on 14 Jun 2013, 06:38 PM
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
0
Stefan
Telerik team
answered on 19 Jun 2013, 04:02 PM
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?
0
Doug
Top achievements
Rank 1
answered on 19 Jun 2013, 05:08 PM
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
0
Stefan
Telerik team
answered on 24 Jun 2013, 06:34 AM
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?
0
Doug
Top achievements
Rank 1
answered on 24 Jun 2013, 05:23 PM
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.
0
Dan
Top achievements
Rank 1
answered on 25 Jun 2013, 04:50 PM
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
0
Doug
Top achievements
Rank 1
answered on 25 Jun 2013, 05:05 PM
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
0
Dan
Top achievements
Rank 1
answered on 26 Jun 2013, 09:26 PM
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
0
Stefan
Telerik team
answered on 27 Jun 2013, 04:32 PM
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 >>
0
Doug
Top achievements
Rank 1
answered on 01 Jul 2013, 02:52 PM
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
0
Dan
Top achievements
Rank 1
answered on 04 Jul 2013, 12:40 PM
No problem, Gary!  I'm glad you got it working! :-)

And thanks, Stefan!

Dan
Tags
ListView
Asked by
Doug
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Doug
Top achievements
Rank 1
Stefan
Telerik team
Dan
Top achievements
Rank 1
Share this question
or