Results 1 to 6 of 6

Thread: [RESOLVED] listview.hwnd problem

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    52

    Resolved [RESOLVED] listview.hwnd problem

    why is there an error in the method when getting the hwnd of a listview from other form.

    Code:
    calling this from form2.
    
    form1.listview1.hwnd returns method error.
    thanks in advance for the reply..

  2. #2

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    52

    Re: listview.hwnd problem

    Code:
    Private Sub gethwnd(frm As Form, lvw As ListView)
    MsgBox frm.lvw.hWnd
    End Sub
    
    Private Sub btn__Click()
    gethwnd Form1, ListView1
    End Sub
    i actually want to create a sub or function to get the hwnd of listview from another form.
    "byref argument type mismatch is the error that i got.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: listview.hwnd problem

    The gethwnd sub should not have two parameters - it should only have lvw , as that exists in its own right and you should not be specifying a parent object for it.

    This line:
    Code:
    MsgBox frm.lvw.hWnd
    is actually asking for an object on Form1 which is called lvw (rather than anything related to your parameter called lvw), which presumably does not exist.

    This will do what you want:
    Code:
    MsgBox lvw.hWnd

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

    Re: listview.hwnd problem

    Add this to your form2:
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim lHwnd As Long
    
        lHwnd = GetHWnd(Form1.ListView1)
        MsgBox lHwnd
    
    End Sub
    
    Private Function GetHWnd(ctl As Control)
    On Error Resume Next
        GetHWnd = ctl.hWnd
    End Function

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2009
    Posts
    52

    Re: listview.hwnd problem

    thank you very guys..it worked now..

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