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

Drag & Drop Image from RadGridView

1 Answer 96 Views
DragAndDrop
This is a migrated thread and some comments may be shown as answers.
Anthony Korkmaz
Top achievements
Rank 1
Anthony Korkmaz asked on 23 Apr 2010, 02:12 PM
Hello,

Q1 2010 VS2008 SL3
I have a GridView that contains an image in the first column, when I drag the row I don't want it to display the PrimaryKey of the row I'm dragging but I want it to show the image that is displayed in the first column.
The problem is that the image is stored in Bytes[] in the database so I cant give the field as a Source to the image control and put it in the DragCue...
I tried something like this in OnContactDragInfo :

            if (e.Options.Status == DragStatus.DragInProgress)
            {            
                ContentControl cue = new ContentControl();
                cue.ContentTemplate = ((Party)(gvContacts.SelectedItem)).Photo as DataTemplate;
                cue.Content = gvContacts.SelectedItem;
                e.Options.DragCue = cue;
            }

But VS is giving this error "Cannot convert type 'byte[]' to 'System.Windows.DataTemplate' " on ((Party)(gvContacts.SelectedItem)).Photo as DataTemplate
NB: The image is displaying fine in the grid view... so can I just take the first item from the GridView whatever it is and give it to the DragCue?

Thanks for your help,

Anthony



1 Answer, 1 is accepted

Sort by
0
Accepted
Kiril Stanoev
Telerik team
answered on 28 Apr 2010, 12:51 PM
Hi Anthony,

I assume the Photo property of the Party business object is the one containing the byte array. If that is the case, you will have to convert the byte array to a BitmapImage. Then create an Image control and set its Source to be the BitmapImage. Finally you can pass the Image as a Content to the cue:

if (e.Options.Status == DragStatus.DragInProgress)
{           
    ContentControl cue = new ContentControl();
    byte[] bytes = ((Party)(gvContacts.SelectedItem)).Photo;
    BitmapImage bmpImage = ImageFromBuffer(bytes);
    Image image = new Image();
    image.Source = bmpImage;
    cue.Content = image;
    e.Options.DragCue = cue;
}
 
 
 
// Method to convert byte array to BitmapImage
public BitmapImage ImageFromBuffer(Byte[] bytes)
{
    MemoryStream stream = new MemoryStream(bytes);
    BitmapImage image = new BitmapImage();
    image.BeginInit();
    image.StreamSource = stream;
    image.EndInit();
    return image;
}

Give it a try and let me know how it goes.

Kind regards,
Kiril Stanoev
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.
Tags
DragAndDrop
Asked by
Anthony Korkmaz
Top achievements
Rank 1
Answers by
Kiril Stanoev
Telerik team
Share this question
or