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

GetDragHintCore is not called

2 Answers 150 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Froggie
Top achievements
Rank 1
Froggie asked on 22 Feb 2012, 11:13 AM
I have a custom VisualItem (class CustomVisualItem : IconListViewVisualItem) and I want a nice image of this item while dragging.
So I wrote this in my VisualItem, but this method never get called (no message in output).
protected override Image GetDragHintCore()
       {
          Debug.WriteLine("GetDragHintCore");
          return GetAsBitmap(Brushes.Yellow, 2, new SizeF(48, 48));      
       }

Is it a bug or my fault?
Ps: There is pretty much no docu on these to methods (GetDragHintCore and GetAsBitmap [what about the parameters?]).

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivan Todorov
Telerik team
answered on 24 Feb 2012, 03:47 PM
Hi Froggie,

Thank you for writing.

The GetDragHintCore is used by the built-in drag drop system and as far as I am aware from your previous threads, you are using the default drag-drop system that the .NET framework provides. That is why it does not get called. The GetAsBitmap method of RadElement returns a snapshot of its element as an Image so it can be used to achieve the desired functionality with the default drag-drop mechanism. The following code snippet demonstrates this:
Cursor dragCursor;
 
void radListView1_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
    e.UseDefaultCursors = false;
    Cursor.Current = dragCursor;
}
 
private void radListView1_DragEnter(object sender, DragEventArgs e)
{
    e.Effect = e.Data.GetDataPresent(typeof(ListViewDataItem)) ? DragDropEffects.Move : DragDropEffects.None;
    if(e.Effect == DragDropEffects.Move)
        Drawcursor(e);
}
 
public static Bitmap SetOpacity(Bitmap original, float opacity)
{
    Bitmap temp = new Bitmap(original.Width, original.Height);
    Graphics g = Graphics.FromImage(temp);
    ColorMatrix cm = new ColorMatrix();
    cm.Matrix33 = opacity;
 
    ImageAttributes ia = new ImageAttributes();
    ia.SetColorMatrix(cm, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
    g.DrawImage(original, new Rectangle(0, 0, temp.Width, temp.Height), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel, ia);
    g.Dispose();
 
    return temp;
}
 
public void Drawcursor(DragEventArgs e)
{
    if (e.Data == null)
        return;
    ListViewDataItem item = e.Data.GetData(typeof(ListViewDataItem)) as ListViewDataItem;
    if (item == null)
        return;
 
    RadElement element = this.radListView1.ListViewElement.ViewElement.GetElement(item);
    Bitmap bmp = SetOpacity(element.GetAsBitmapEx(Color.Transparent, 0, new SizeF(1, 1)), 0.5f);
    dragCursor = new Cursor(bmp.GetHicon());
    bmp.Dispose();
}

As to your notice about the documentation, we are aware that a part of our publicly accessible API is not well documented and we are constantly working on improving it.

Thank you for your feedback. Should you have any further questions, feel free to write back.

Regards,
Ivan Todorov
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Froggie
Top achievements
Rank 1
answered on 24 Feb 2012, 04:04 PM
Thank you!
That solution works like a charm.
Right now I'm testing this solution when scrolling while dragging.
Tags
ListView
Asked by
Froggie
Top achievements
Rank 1
Answers by
Ivan Todorov
Telerik team
Froggie
Top achievements
Rank 1
Share this question
or