How to drag an text item from a listview to my custom host designer?

I have a listview which has text items, not toolboxitems, should be dragged over controls in my custom host designer. I'd like to enable the link dragdropeffect when drag a listviewitem over controls. When user start draggin from the listview, the following codes are used:

//selectedMappedControl is the text of the selected listview item
if
(!string.IsNullOrEmpty(selectedMappedControl)){

DataObject d = new DataObject(selectedMappedControl);

lvMapped.DoDragDrop(d, DragDropEffects.Link);
}

I used a global behavior to capture the dragenter event when the listviewitem is dragged into the host designer.

public override void OnDragEnter(Glyph g, DragEventArgs e){
...

if (e.Data.GetDataPresent(DataFormats.Text))
{
object obj = e.Data.GetData(DataFormats.Text);
if (obj != null)
{
if(e.Effect ==
DragDropEffects.Link){//do something}
base.OnDragEnter(g, e);
}
}
...
}

However, the e.Effect is not consistently set to 'link', in fact most of the time, the effect captured in the behavior's onfragenter is 'none'. It seems to me there're some middle steps that I cannot control.  Certainly, the cursor won't show the correct 'link' image when dragging over the host designer or controls hosted in the designer.

Please push me to the right direction on this.

Thanks,
Alan



Answer this question

How to drag an text item from a listview to my custom host designer?

  • How to drag an text item from a listview to my custom host designer?