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

drag'n'drop files to a gridview

9 Answers 398 Views
GridView
This is a migrated thread and some comments may be shown as answers.
andi
Top achievements
Rank 1
andi asked on 02 Apr 2008, 01:11 PM
i've got a gridview where files stored in a database are displayed. now i want to drag'n'drop new files to the gridview and store them by code in the database.

is it possible to drag'n'drop any file or folder structure to the gridview?

am i right to use the DragDrop event?

how can i get the properties of the dropped file (fileName, etc...) to handle the necessary operation by vb.net code?

thanks, andi

9 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 02 Apr 2008, 02:35 PM
Hello andi,

Thank you for this question.

You are right about using the DragDrop event. You should aslo set the AllowDrop property to true and handle the DragEnter event in order to allow dragging over the RadGridView.

Please, refer to the code snippet below:

RadGridView1.AllowDrop = True 
Private Sub RadGridView1_DragEnter(ByVal sender As System.ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles RadGridView1.DragEnter  
    If e.Data.GetDataPresent(DataFormats.FileDrop) Then 
        e.Effect = DragDropEffects.All  
    Else 
        e.Effect = DragDropEffects.None  
    End If 
End Sub 
 
Private Sub RadGridView1_DragDrop(ByVal sender As System.ObjectByVal e As System.Windows.Forms.DragEventArgs) Handles RadGridView1.DragDrop  
    Dim fileNames() As String = CType(e.Data.GetData(DataFormats.FileDrop, False), String())  
    Dim i As Integer = 0  
    Do While (i < fileNames.Length)  
        Me.RadGridView1.Rows.Add(fileNames(i))  
        i = (i + 1)  
    Loop 
End Sub 
 

I hope this helps. Do not hesitate to contact me, if I can help you further.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
andi
Top achievements
Rank 1
answered on 03 Apr 2008, 09:12 AM
hi and thanks for your answer!

how can i differ betwenn file and directories that are dropped to the control?

can i also get different properties of the dropped object? e.g. FileName, FilePath, FileType, FileSize?

thank you!

andi
0
andi
Top achievements
Rank 1
answered on 03 Apr 2008, 12:24 PM
hi again,

i`m wondering because nobody has answered my questions yet... did you understand what i mean or is my english too bad?

thanks, andi
0
Jack
Telerik team
answered on 03 Apr 2008, 03:54 PM
Hello andi,

Thank you for your patience.

The full FilePath is accessible through the fileNames array obtained from the GetData method when processing the DragDrop event. You can get additional file information by using the FileInfo class.

Please, take a look at the following sample code:

Dim fi As IO.FileInfo = New IO.FileInfo(fileNames(i)) 
FileName = fi.Name 
FilePath = fi.FullName 
FileType = fi.Extension 
FileSize = fi.Length 
 

I hope this helps. Do not hesitate to contact me again, if you have other questions.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
andi
Top achievements
Rank 1
answered on 04 Apr 2008, 11:19 AM
hi and thanks for your answer!

drag'n'drop now works fine. but i've got another problem in between:

i cannot drop email-attachements out of my outlook mail client onto the gridview.

isn't it possible at all?

andi
0
Jack
Telerik team
answered on 04 Apr 2008, 03:31 PM
Hi andi,

Yes, it is possible to drag & drop email attachments.

The email attachment isn't a real file on your hard disk. It contains information about the file name and its contents. It is possible to read this information to save it as a file.

Microsoft doesn't provide an official solution for this issue. Nevertheless, there are some solutions available on the web. Take a look at the links below:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2970481&SiteID=1
http://bytes.com/forum/thread213727.html

I hope this helps. Let me know, if I can help you further.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Pawz
Top achievements
Rank 1
answered on 07 Apr 2008, 08:34 AM
I think telerik deserves a +1 support skill bonus for answering questions not even remotely related to their controls! Nice :)
0
Mirko
Top achievements
Rank 1
answered on 15 Sep 2009, 07:46 AM
Hello,

It's possible drag a row from gridview to filesystem ( windows folder, desktop,etc)?

Mirko
0
Victor
Telerik team
answered on 17 Sep 2009, 12:04 PM
Hi Mirko,

I am afraid that we do not support this particular case. In order to implement such functionality you must use the native Win32 API since the current windows forms drag and drop mechanism supports only managed drop targets. I am looking forward to your response.

Sincerely yours,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
andi
Top achievements
Rank 1
Answers by
Jack
Telerik team
andi
Top achievements
Rank 1
Pawz
Top achievements
Rank 1
Mirko
Top achievements
Rank 1
Victor
Telerik team
Share this question
or