简体   繁体   中英

How do I declare a reference to an ActiveX “ListView” Control in Access VBA?

I'm using Access 2003.

In "References" (Tools > References > Browse...), I've added in "Microsoft Windows Common Controls 6.0 (SP6)" (c:\\windows\\system32\\mscomctl.ocx) and I've created/inserted an instance of the control "Microsoft ListView Control 6.0 (SP6)" on a Form and given the control the Name "MyListView".

I wanted to decorate MyListView with some custom methods so I've created a class ("DecoratedListView") which contains a member field ("lvw").

I want 'lvw' to point/reference MyListView, but I don't know what reference type to use in its declaration. Importantly, I also want to capture lvw's ColumnClick event.

I've tried:

Public WithEvents lvw As Object
Public WithEvents lvw As Control
Public WithEvents lvw As MSComctlLib.ListView.2

and none works when I

set lvw = MyForm.MyListView

Can anyone explain how I should create the reference (lvw) to the existing object (MyListView)?

Access can't really handle that sort of thing.

The OnClick should be available on your MyForm though, but you can't see it in the Event tab in properties. ActiveX Controls are too complicated for that. Instead, go into the code and choose MyListView in the combobox on the top left. You'll then find the extended ActiveX events in the combobox on the top right. One of them is ColumnClick.

Not sure what your full intentions are, but if you want to sort of mimic an isolated DecoratedListView class then create a special form that only includes a ListView control and use it as a subform for other forms. You can refer to the ListView from the parent Form as you would any other subform control object. Parent specific code can be run from the listview subform by checking the me.parent.name object which is basically the parent form. You can even call subform's listview events by changing the default Private Sub to Public Sub.

I can't comment yet, so I'll type it as an answer. Did you look in View, Object Browser to see what methods and properties are available for that object? You should be able to write what you want using that information, assuming what you want is possible.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM