Results 1 to 9 of 9

Thread: Create Listview Programatically

  1. #1

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    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

  2. #2
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    468

    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:
    1. Private WithEvents MyListView As ListView
    2.  
    3. Private Sub Form_Load()
    4.   Set MyListView = Controls.Add("MSComctlLib.ListViewCtrl.2", "MyListView", Me)
    5.   MyListView.Visible = True
    6. End Sub
    7.  
    8. Private Sub MyListView_GotFocus()
    9.   Debug.Print "I'm here!"
    10. End Sub
    11.  
    12. Private Sub MyListView_LostFocus()
    13.   Debug.Print "I'm gone!"
    14. End Sub

    Of course, you'll need to reference the MsComCtl.ocx in your project.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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...

  4. #4

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    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

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Create Listview Programatically

    you need to add a reference to "Microsoft Windows Common Controls 6.0"

  6. #6

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    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

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Create Listview Programatically

    It's under the "Make" tab in the project properties. It's a check box near the bottom.

  8. #8
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    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

  9. #9

    Thread Starter
    Hyperactive Member Jenova's Avatar
    Join Date
    Feb 2006
    Location
    Googleplex
    Posts
    413

    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
  •  



Click Here to Expand Forum to Full Width