473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MS ListView control and OLEDragDrop

topher23
234 Expert 100+
I've had a request for database functionality that I've never done before, and several hours of research have led me nowhere. Here's the skinny:

My users would like to be able to drag a picture file from a digital camera onto a form and have it link to the record in the form.

Research led me to the MS ListView control as a good Drag-And-Drop activator, but I can't get an OLEDragDrop event that will work. I used the example I found somewhere

Expand|Select|Wrap|Line Numbers
  1. Private Sub ControlName_OLEDragDrop(Data As MSComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, Y As Single)    
  2.  
  3.     Dim sF As String
  4.     Dim J As Integer
  5.  
  6.     For J = 1 To Data.Files.Count
  7.         sF = sF & Data.Files(J) & vbCrLf
  8.     Next
  9.     MsgBox sF
  10.  
  11. End Sub
  12.  
and I get

"The expression you entered as the event property setting produced the following error: The procedure declaration does not match description of event procedure having the same name."

If anyone has experience with this control, please give me some pointers! MSDN has been utterly useless on this subject.
Jan 13 '10 #1

✓ answered by ADezii

Hello topher23:
I wrote some code for you that will allow you to Drag-N-Drop either Single or Multiple Files from Windows Explorer into a ListView Control named ListView1. Once dropped, all of the File's Absolute Paths will be displayed within the context of the ListView Control under a single Column Header named Absolute File Path. The code has been thoroughly tested and is fully operational, any questions feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
  2. Dim varFileName As Variant
  3.  
  4. 'Create an object variable for the ColumnHeader object.
  5. Dim clmX As ColumnHeader
  6.  
  7. 'Create a variable to add ListItem objects.
  8. Dim itmX As ListItem
  9.  
  10. 'Add 1 Column Header. The width of the Column Header is the width
  11. 'of the ListView Control.
  12. Set clmX = ListView1.ColumnHeaders.Add(, , "Absolute File Path", ListView1.Width)
  13.  
  14. ListView1.BorderStyle = ccFixedSingle       'Set BorderStyle property.
  15. ListView1.View = lvwReport                  'Set View property to Report.
  16. ListView1.OLEDropMode = ccOLEDropManual     'Initiate DROP Operation
  17.  
  18. If Data.GetFormat(ccCFFiles) Then
  19.   For Each varFileName In Data.Files
  20.     Set itmX = ListView1.ListItems.Add(, , varFileName)
  21.   Next
  22. Else    'Data is not in the desired Format
  23.     Effect = ccOLEDropEffectNone
  24. End If
  25. End Sub

4 13685
MMcCarthy
14,534 Expert Mod 8TB
As this is a VB6 event you should also post this in Visual Basic. You might have better luck finding someone who is familiar with it. Unfortunately, I've never used it.

I know it's stating the obvious but have you a reference to the VB6 library.
Jan 13 '10 #2
ADezii
8,834 Expert 8TB
Hello topher23:
I wrote some code for you that will allow you to Drag-N-Drop either Single or Multiple Files from Windows Explorer into a ListView Control named ListView1. Once dropped, all of the File's Absolute Paths will be displayed within the context of the ListView Control under a single Column Header named Absolute File Path. The code has been thoroughly tested and is fully operational, any questions feel free to ask.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ListView1_OLEDragDrop(Data As Object, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
  2. Dim varFileName As Variant
  3.  
  4. 'Create an object variable for the ColumnHeader object.
  5. Dim clmX As ColumnHeader
  6.  
  7. 'Create a variable to add ListItem objects.
  8. Dim itmX As ListItem
  9.  
  10. 'Add 1 Column Header. The width of the Column Header is the width
  11. 'of the ListView Control.
  12. Set clmX = ListView1.ColumnHeaders.Add(, , "Absolute File Path", ListView1.Width)
  13.  
  14. ListView1.BorderStyle = ccFixedSingle       'Set BorderStyle property.
  15. ListView1.View = lvwReport                  'Set View property to Report.
  16. ListView1.OLEDropMode = ccOLEDropManual     'Initiate DROP Operation
  17.  
  18. If Data.GetFormat(ccCFFiles) Then
  19.   For Each varFileName In Data.Files
  20.     Set itmX = ListView1.ListItems.Add(, , varFileName)
  21.   Next
  22. Else    'Data is not in the desired Format
  23.     Effect = ccOLEDropEffectNone
  24. End If
  25. End Sub
Jan 13 '10 #3
topher23
234 Expert 100+
Thanks, ADezii, that worked beautifully! It looks like the problem was that in VB6 the variable type for Data is MsComCtlLib.DataObject (or, on some of the examples I found, just DataObject) but in VBA it's just Object. When I change the Data variable back to DataObject in your code I get the same error.

With any luck, this thread will be able to help others who also had no luck searching for a proper way to use the method in Access.
Jan 13 '10 #4
ADezii
8,834 Expert 8TB
Glad it worked out for you, topher23.
Jan 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below....
2
by: Ken | last post by:
Hi all, Please help! I'm attempting to apply tooltips to each individual item in VB.Net's Listview control. In VB6 it was easy - you just did the following (assumes "myListView" is the name of...
7
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
3
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set...
12
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. ...
10
by: Rob | last post by:
VS 2005 How can you tell if a value is contained in a specific column (let's say column 1 named Status) of a ListView ? In a list box you could go... If ListBox1.Items.Contains(strWhatever)...
1
by: dshubhangi | last post by:
hi I've set richtextbox OLEDropMode Manual,catched OLEDragDrop event & in that event written below code Richtextbox1.OLEObjects.add ,,data.files(1) Now I'm able to catch OLEDragDrop as well as...
5
by: Mark Olbert | last post by:
How do I get the DataPager and ListView to play nice together when I use a custom datasource? In my webpage, I use linq to pull data from a SqlServer database and assign the resulting...
4
by: Brian Gaze | last post by:
I have created a ListView control and have bound this to a datasource. Within the ItemTemplate of the ListView I have added another ListViewControl which is databound in the code behind. The idea...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.