drag'n'drop files to a gridview

10 posts, 0 answers
  1. andi
    andi avatar
    34 posts
    Member since:
    Jan 2008

    Posted 02 Apr 2008 Link to this post

    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
  2. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 02 Apr 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. andi
    andi avatar
    34 posts
    Member since:
    Jan 2008

    Posted 03 Apr 2008 Link to this post

    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
  5. andi
    andi avatar
    34 posts
    Member since:
    Jan 2008

    Posted 03 Apr 2008 Link to this post

    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
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 03 Apr 2008 Link to this post

    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
  7. andi
    andi avatar
    34 posts
    Member since:
    Jan 2008

    Posted 04 Apr 2008 Link to this post

    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
  8. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 04 Apr 2008 Link to this post

    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
  9. Pawz
    Pawz avatar
    51 posts
    Member since:
    Aug 2007

    Posted 07 Apr 2008 Link to this post

    I think telerik deserves a +1 support skill bonus for answering questions not even remotely related to their controls! Nice :)
  10. Mirko
    Mirko avatar
    8 posts
    Member since:
    May 2007

    Posted 15 Sep 2009 Link to this post

    Hello,

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

    Mirko
  11. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 17 Sep 2009 Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready