Results 1 to 7 of 7

Thread: [RESOLVED] Adding listview at runtime

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Resolved [RESOLVED] Adding listview at runtime

    As I can use this :

    VB Code:
    1. Set Text1 = ctlForm.Controls.Add("VB.TextBox", "TextBox1")

    For a textbox, what would be the equivelant to VB.TextBox for a listview? It doesn't like VB.ListView...


    Has someone helped you? Then you can Rate their helpful post.

  2. #2

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: Adding listview at runtime

    Used this : "MSComctlLib.ListViewCtrl.2"


    Has someone helped you? Then you can Rate their helpful post.

  3. #3

  4. #4

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] Adding listview at runtime

    Quote Originally Posted by RhinoBull
    Just be aware manavo that since Listview is not an Intrinsic control then you must add license to licenses collection or it may fail on the destination machine otherwise.
    Oops What is that? I read about it but I thought since it worked on my PC it'll work fine


    Has someone helped you? Then you can Rate their helpful post.

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: [RESOLVED] Adding listview at runtime

    It basically means that it much safer to use Control Array with any non Intrinsic control (those that are not part of VB default controls).
    Here is a quote from MSDN:
    Add Method (Licenses Collection)

    Adds a license to the Licenses collection and returns the license key.

    Syntax

    object.Add (ProgID, LicenseKey)

    The Add method syntax has these parts:

    Part Description
    object Required. Anobject expression that evaluates to an object in the Applies To list.
    ProgID Required. A string that specifies the control for which a license key will be added.
    LicenseKey Optional. A string that specifies the license key.


    Remarks

    Use the Add method whenever you want to dynamically add a control that requires a license key. For more information about controls that require license keys, see "Licensing Issues for Controls" in the See Also list.

    When you compile a user control that requires a license key, and you want to dynamically add that control to an existing application, you must use the Add method for the Licenses collection in two different ways.

    First, use the method to return the license key that is hard-coded into a user control. Second, use the method to add the same license key to the Licenses collection before adding the user control to the Controls collection.

    In most cases, you will have to use the method in both ways in order to properly deploy a compiled user control. The steps for this are outlined below.

    After you have compiled a user control that requires a license key, use the Add method to return the license key. Store that license key where it can be retrieved by the deployed application. For example, the example below writes the key to a file. You could also store it in a database, or in the Windows registry.
    VB Code:
    1. Private Sub GenerateLicenseKey()
    2.    Dim intFile As Integer
    3.    intFile = FreeFile
    4.    ' Open a file to write the license key to.
    5.    Open "c:\Temp\Ctl_Licenses.txt" For Output As #intFile
    6.    Dim strLicense As String
    7.    strLicense = Licenses.Add("prjWeeks.WeeksCtl")
    8.    ' Write the license key to the file.
    9.    Write #intFile, strLicense
    10.    Close #intFile
    11. End Sub
    When you deploy your control, the deployed application adds the license key to the Licenses collection before adding the control to the Controls collection. (Of course, the control must have been installed on the machine as well.) The code example below adds the license key, then adds the control:
    VB Code:
    1. Option Explicit
    2. Dim WithEvents extObj As VBControlExtender
    3.  
    4. Private Sub LoadDynamicControl()
    5.    Dim intFile As Integer
    6.    intFile = FreeFile
    7.    Open "c:\Download\Ctl_Licenses.txt" For Input As #intFile
    8.    Dim strKey As String
    9.    ' On the client machine, read the license key from the file.
    10.    Input #intFile, strKey
    11.    Licenses.Add "prjWeeks.WeeksCtl", strKey
    12.    Close #intFile
    13.    Set extObj = Controls.Add("prjWeeks.WeeksCtl", "ctl1")
    14.    With Controls("ctl1")
    15.       .Visible = True
    16.    End With
    17. End Sub
    When To Add a License Key
    When you create a user control and you want to distribute the control for dynamic control addition, you must consider the following question: Does the user control contain only intrinsic controls? If the answer is yes, then ask, "Do I want to require that the end user have a license key in order to use the control?" If the answer to both questions is "yes," then be sure to check the Require License Key option on the General tab of the Project Properties dialog box.

    Note Even if you clear the Require License Key option, a user control that contains third-party controls will still require a license key.

    When No License Key Is Needed
    There are two circumstances when you do not have to add a license key in order to add a control to the Controls collection:

    When the control is an intrinsic control and you have not checked the Require License Key option.


    When you add a control that is referenced in the project. In other words, if the control is present in the Toolbox.
    Note When you do have a control in the Toolbox and you plan to add that control only at run time, be sure to clear the Remove Information About Unused ActiveX Controls option on the Make tab of the Project Properties dialog box; otherwise, trying to add the control will fail.

  6. #6

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: [RESOLVED] Adding listview at runtime

    I'll have to read through that then... Thanks RB


    Has someone helped you? Then you can Rate their helpful post.

  7. #7

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