Results 1 to 12 of 12

Thread: Listview into Subroutine

  1. #1

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Listview into Subroutine

    Is it possible to turn this into a subroutine:


    Private Sub lvwCust_ItemClick(ByVal item As ListItem)
    txtCustID.Text = item.Text
    cmbTitle.Text = item.SubItems(1)
    txtFirstName.Text = item.SubItems(3)
    txtSurname.Text = item.SubItems(2)
    txtAddress1.Text = item.SubItems(4)
    txtAddress2.Text = item.SubItems(5)
    txtTown.Text = item.SubItems(6)
    txtCounty.Text = item.SubItems(7)
    txtPostCodei.Text = Left(item.SubItems(8), 4)
    txtPostCodeii.Text = Right(item.SubItems(8), 3)
    txtTelephone.Text = item.SubItems(9)
    txtEmailAddress.Text = item.SubItems(10)
    End Sub

    I want it as a subroutine since I want to call it from multiple subroutines. I've tried calling this, but I don't know what to input into the parameter (the ByVal bit)

    Any help guys? Thanks in advance if i get any help.

  2. #2
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Listview into Subroutine

    Have you tried calling the event for another portion of your code like this:

    VB Code:
    1. Call lvwCust_ItemClick(1)
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  3. #3

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Listview into Subroutine

    yes, still nothing, but i'll try again.

  4. #4

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Listview into Subroutine

    it doesnt work. It says type mismatch.

    It does the same thing if i do

    VB Code:
    1. Call lvwCust_ItemClick("1")

  5. #5
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Listview into Subroutine

    Have you added any items to the listview? "ByVal item As ListItem" has to be one of the items you added. It's a string.

    I did this very quickly from the help file:
    VB Code:
    1. Private Sub Form_Activate()
    2.    Dim itmX As ListItem
    3.    
    4.    ListView1.ColumnHeaders.Add , , "Author", ListView1.Width / 3
    5.    ListView1.ColumnHeaders.Add , , "Author ID", ListView1.Width / 3, lvwColumnCenter
    6.    ListView1.ColumnHeaders.Add , , "Birthdate", ListView1.Width / 3
    7.  
    8.    Set itmX = ListView1.ListItems.Add(, , "Stevenson")
    9.    itmX.SubItems(1) = "1"
    10.    itmX.SubItems(2) = "1800"
    11.  
    12. End Sub
    If you click on the item (there's only one) and break in the listview itemclick sub, you'll see that Item is "Stevenson".

  6. #6

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Listview into Subroutine

    yes i have previously entered data into the listview from data in a database table (access - ADODB). I've added it fine, and I've done breaks in my code, tried a couple of methods and it still wont budge

    I've done:
    • Breaks in the code
    • calling the actual thing
    • Replacing the (1) bit with various things


    If there is nothing you can come up with to solve my problem then that's ok.

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Listview into Subroutine

    If you call it from another place, you would have to pass a listitem, and not a string, or an integer.

    Where should the data come from, that is to be placed in the textboxes, if you call the sub from another place?
    Frans

  8. #8

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Listview into Subroutine

    it comes from a access database (the listview) but i want it so when the form loads up it has the first listview property and sticks it into the textboxes

  9. #9
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Listview into Subroutine

    VB Code:
    1. Call lvwCust_ItemClick(lvwCust.ListItems(1))
    Frans

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Listview into Subroutine

    Wouldn't just selecting the first listitem fire the item click event?

  11. #11

    Thread Starter
    Fanatic Member kregg's Avatar
    Join Date
    Feb 2006
    Location
    UK
    Posts
    524

    Re: Listview into Subroutine

    Frans C - That doesn't work

    leinad31 - It does fire it up, but the thing is I need it so when the form loads then it fires up.

  12. #12
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Listview into Subroutine

    What is the problem?
    Is there an error message?

    You should load the listview first of course.
    Frans

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