|
||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionWell this is just a pretty straightforward example of how to create a drag and drop feature that can list the file paths of the files that were dragged into the Using the CodeThere are really only two things that are needed to create a drag and drop feature... First: You need to have a Second: You will need to have a Private Sub lstFiles_DragEnter(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFiles.DragEnter
'SET THE PROPER ACTION FOR FILE DROP....BY USING THE FILEDROP METHOD TO COPY
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
e.Effect = DragDropEffects.Copy
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub lstFiles_DragDrop(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DragEventArgs) Handles lstFiles.DragDrop
'NOW THIS IS WHAT SHOULD TAKE PLACE FOR THE APP TO ADD THE TEXT FILE
' PATHS TO THE LIST VIEW ITEMS
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim filePaths As String() = CType(e.Data.GetData_
(DataFormats.FileDrop), String())
For Each filePath As String In filePaths
Dim chkExt As String = _
My.Computer.FileSystem.GetFileInfo(filePath).Extension
'I'M STILL LEARNING SO PLEASE DON'T CRITISIZE ME TO BAD....
'THIS IS THE ONLY METHOD THAT I KNOW HOW TO CALCULATE THE FILE SIZE....
Dim chkSize As String = _
My.Computer.FileSystem.GetFileInfo(filePath).Length
chkSize = chkSize / 1024
'THIS IS WHAT I USED TO ROUND THE SIZE TO 2 DECIMAL POINTS...
Dim d As Decimal
d = Decimal.Round(chkSize, 2, MidpointRounding.AwayFromZero)
'THIS WILL ADD THE FILEPATHS AND THE FILES SIZE TO THE LIST VIEW
Dim LI As ListViewItem
LI = Me.lstFiles.Items.Add(filePath)
LI.StateImageIndex = 0
LI.SubItems.Add(d & " kb")
Next filePath
End If
End Sub
Points of InterestPretty simple really. I was just bored at the office and wanted something to do. History
|
|||||||||||||||||||||||||||||||||||||||||||||||