|
-
Oct 31st, 2006, 05:43 PM
#1
Thread Starter
Hyperactive Member
Create Listview Programatically
You can use code i.e. "WithEvents" to build a control at runtime. However, this only works for controls that are integrated in to the IDE. How would i generate a Listview the same way programatically.
Regards,
Jenova
-
Oct 31st, 2006, 05:54 PM
#2
Hyperactive Member
Re: Create Listview Programatically
You can add it dynamically just like a CommandButton. The hard part is knowing the correct ProgID. A little Googling and voila:
VB Code:
Private WithEvents MyListView As ListView
Private Sub Form_Load()
Set MyListView = Controls.Add("MSComctlLib.ListViewCtrl.2", "MyListView", Me)
MyListView.Visible = True
End Sub
Private Sub MyListView_GotFocus()
Debug.Print "I'm here!"
End Sub
Private Sub MyListView_LostFocus()
Debug.Print "I'm gone!"
End Sub
Of course, you'll need to reference the MsComCtl.ocx in your project.
-
Oct 31st, 2006, 06:03 PM
#3
Re: Create Listview Programatically
To get it to work, you would have to uncheck the "Remove information about unused activeX controls" in the project properties.
You don't have to do that if you actually use something from that OCX by adding it from the toolbox. If you do it all dynamically, VB will remove the reference to that OCX because it doesn't know you are using it anywhere...
-
Oct 31st, 2006, 06:03 PM
#4
Thread Starter
Hyperactive Member
Re: Create Listview Programatically
I tried something similar to that but it does not work. if you reference the control then you get an error saying that it can not be referenced and to un-reference it. If you don't refrence it you just get an error saying that the user defined type has not been defined.
Regards,
Jenova
-
Oct 31st, 2006, 06:04 PM
#5
Re: Create Listview Programatically
you need to add a reference to "Microsoft Windows Common Controls 6.0"
-
Oct 31st, 2006, 06:10 PM
#6
Thread Starter
Hyperactive Member
Re: Create Listview Programatically
If by add a reference you mean tick the Microsoft Common Controls 6.0 in the components dialog, i did and it told me to unreference it. How do i uncheck the "Remove information about unused activeX controls" i cant find it in the project properties
Regards,
Jenova
-
Oct 31st, 2006, 06:18 PM
#7
Re: Create Listview Programatically
It's under the "Make" tab in the project properties. It's a check box near the bottom.
-
Oct 31st, 2006, 09:43 PM
#8
Re: Create Listview Programatically
Also for Microsoft Windows Common Controls 5.0 (comctl32.ocx <- Supports XPstyle)
http://www.vbforums.com/showpost.php...14&postcount=4
-
Nov 1st, 2006, 03:52 AM
#9
Thread Starter
Hyperactive Member
Re: Create Listview Programatically
I have been using the Working Model Edition so i think that is why it did not work. I will try the professional edition when i get home from college. Cheers guys. 
Regards,
Carl
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|