CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 1999
    Posts
    4

    How do I drag files from a File list box and open them in a text box on the same form?



    Thanks for your help Chris, but here was what I meant to say. sorry! O.k. I am building an HTML editor. O.k on my form I have a Drive List Box, Directory List Box and a File List Box and a Text box. now I know how to make them work, so that I can change the directory, and it will show the folders in the directory list, which shows the files in the File List Box.


    But what I wanna do is, i want to be able to drag files from the File List Box and have them open in the Text Box on the same form. I wanna be able to allow the user to drag an HTML file from the File List Box and have it open in the Text Box. Can I do? I sure hope so That's the only thing I can't figure out, is how to drag the file and have it open in the text box. Can any one help me? Thanks for any help you can give me.

  2. #2
    Join Date
    May 1999
    Location
    Oxford UK
    Posts
    1,459

    Re: How do I drag files from a File list box and open them in a text box on the same form?



    Hi Shannon


    It's really the same answer, with a bit more code in the Text1_OleDragDrop procedure.


    Instead of a Text String being passed to the dragdrop procedure, the Data object contains the list of filenames selected from the file list box in the '.files' property.


    Take a form, add the filelistbox (File1) and a TextBox (Text1) and set the following properties on the textbox


    MultiLine = True

    ScrollBars = Both


    Now paste the following code into the form :


    Option Explicit


    Private Sub Form_Load()



    With File1

    .Path = "c:"

    .Pattern = "*.txt"

    .OLEDragMode = 1 ' automatic

    End With



    Text1.OLEDropMode = 1 ' manual



    End Sub


    Private Sub Text1_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)



    Dim sBuffer As String

    Dim lLen As Long

    Dim lFileNum As Long



    lFileNum = FreeFile

    '

    ' Data.Files(1) contains the first selected filename from the list box

    '

    Open Data.Files(1) For Binary Access Read As 1

    '

    ' This time I'm demonstrating reading the whole file at once

    '

    lLen = LOF(lFileNum)


    sBuffer = String$(lLen, vbNullChar)



    Get #1, , sBuffer



    Close #1



    Text1.Text = sBuffer



    End Sub



    Regards


    Chris Eastwood

    Software Engineer

    ACNielsen Ltd


    CodeGuru - the website for developers

    http://www.codeguru.com



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured