Results 1 to 9 of 9

Thread: Pass ListView as parameter

  1. #1

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287

    Pass ListView as parameter

    Sups
    I have this decleration:
    VB Code:
    1. Public Sub ShowBoard(Key As String, List As ListView)
    2. ...
    3. [B]If frmMain[COLOR=red].List[/COLOR].SelectedItem.Index <> 1 Then[/B]
    4. ...
    5. End Sub

    I have two ListView controls, and in the Click event, I want the two controls to performe the same action. I wrote 1 public sub as you can see, and i'm passing the ListView control as a parameter:
    VB Code:
    1. Private Sub List1_Click()
    2.     Call ShowBoard("Mouse", List1)
    3. End Sub

    The problem is that I get an Error that it cant recodnize the control: "Method or data member not found"

    How can I resolve that?

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Since you pass the ListView control to your procedure then there is no reason to reference the form. Change your statement to

    If List.SelectedItem.Index <> 1 Then

  3. #3

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287
    Yup..Tha'ts it tnx

  4. #4

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287
    Is there a way to know which listview control is being used?
    Seems like this dont work:
    VB Code:
    1. If List = frmMain.List2 Then

  5. #5
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    If List is frmMain.List2 Then

  6. #6
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    Code:
    If List.Name="List2" then
    
    ...

  7. #7

    Thread Starter
    Hyperactive Member Stiletto's Avatar
    Join Date
    Aug 2002
    Location
    Jerusalem, Israel
    Posts
    287
    One more question:
    I have a listview with 2 columns on it.
    How do I get the text of an item in the second column?
    God damnit...This control is too complicated for me

  8. #8
    Fanatic Member
    Join Date
    Sep 2000
    Location
    Over There
    Posts
    522
    item.subitems(1)

    where item is a list item.

    VB Code:
    1. 'second column
    2. listview.selecteditem.subitems(1)
    It Never Fails. Everytime I try to make a program idiot proof, the world makes a better idiot.

  9. #9
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    The View style must be Report to get columns. Use the ListSubItem property.

    VB Code:
    1. Dim objItem As ListItem
    2.    
    3.     With ListView1
    4.         .View = lvwReport
    5.         .ColumnHeaders.Add , , "Column 1"
    6.         .ColumnHeaders.Add , , "Column 2"
    7.         .ColumnHeaders.Add , , "Column 3"
    8.    
    9.         Set objItem = .ListItems.Add(, , "Testing 1")
    10.         objItem.ListSubItems.Add , , "Sub Item 1"
    11.         objItem.ListSubItems.Add , , "Sub Item 2"
    12.    
    13.         Set objItem = .ListItems.Add(, , "Testing 2")
    14.         objItem.ListSubItems.Add , , "Sub Item 1"
    15.         objItem.ListSubItems.Add , , "Sub Item 2"
    16.     End With

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