Results 1 to 13 of 13

Thread: type mismatch error on listview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    type mismatch error on listview

    keeps giving me run time error 13

    VB Code:
    1. Private Sub Command1_Click()
    2.         Dim itm As ListItem
    3.         Set itm = ListView1.ListItems.Add(Text:="hi")
    4.         itm.SubItems(1) = "b"
    5.         itm.SubItems(2) = "a"
    6. End Sub

    any ideas guys whats wrong

  2. #2
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: type mismatch error on listview

    Quote Originally Posted by Pouncer
    keeps giving me run time error 13

    VB Code:
    1. Private Sub Command1_Click()
    2.         Dim itm As ListItem
    3.         Set itm = ListView1.ListItems.Add(Text:="hi")
    4.         itm.SubItems(1) = "b"
    5.         itm.SubItems(2) = "a"
    6. End Sub

    any ideas guys whats wrong
    VB Code:
    1. Private Sub Command1_Click()
    2.     With ListView1
    3.         .ListItems.Add , , "row 1, column 1"
    4.         .ListItems(1).SubItems(1) = "row 1, column 2"
    5.    
    6.         .ListItems.Add , , "row 2, column 1"
    7.         .ListItems(2).SubItems(1) = "row 2, column 2"
    8.     End With
    9. End Sub
    works for me.

    or
    VB Code:
    1. Private Sub Command1_Click()
    2.     Dim itm As ListItem
    3.  
    4.     Set itm = ListView1.ListItems.Add(, , "text here")
    5.     itm.SubItems(1) =  "text here"
    6.     itm.SubItems(2) = "text here"
    7. End Sub
    I believe
    Attached Files Attached Files

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: type mismatch error on listview

    what the hell is going on,

    on yours

    Private Sub Command1_Click()
    Dim itm As ListItem

    Set itm = ListView1.ListItems.Add(, , "text here")
    itm.SubItems(1) = "text here"
    itm.SubItems(2) = "text here"
    End Sub


    works fine,
    i do exatly the same on mine, and i get same mismatch error

  4. #4
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: type mismatch error on listview

    Quote Originally Posted by Pouncer
    what the hell is going on,

    on yours

    Private Sub Command1_Click()
    Dim itm As ListItem

    Set itm = ListView1.ListItems.Add(, , "text here")
    itm.SubItems(1) = "text here"
    itm.SubItems(2) = "text here"
    End Sub


    works fine,
    i do exatly the same on mine, and i get same mismatch error
    This is yours
    Set itm = ListView1.ListItems.Add(Text:="hi")
    and this is mine
    Set itm = ListView1.ListItems.Add(, , "text here")
    if you download my example which has been tested, it works. so you should review your code to see if you have done something wrong

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: type mismatch error on listview

    i downloaded yours and check yours, i do exactly the same..

    i made a new project to test it, it works in the new peroject

    but on my project where i have all my stuff when i add a new listview box and put the code it, it gives type mismatch

    i even tried it with a new form in my project, still the same problem

  6. #6
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: type mismatch error on listview

    Quote Originally Posted by Pouncer
    i downloaded yours and check yours, i do exactly the same..

    i made a new project to test it, it works in the new peroject

    but on my project where i have all my stuff when i add a new listview box and put the code it, it gives type mismatch

    i even tried it with a new form in my project, still the same problem
    you didnt do the same because have a look at the parts that highlighted in red and bolded
    VB Code:
    1. Set itm = ListView1.ListItems.Add[b][color=red](Text:="hi")[/color][/b][color=red][/color]

    mine
    VB Code:
    1. Set itm = ListView1.ListItems.Add[b][color=red](, , "text here")[/color][/b][color=red][/color]

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: type mismatch error on listview

    yeah i used that code you gave, same prblem

    could it be something to do with listview box properties?

    i set the view property as lvwReport, any other properties?

  8. #8
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: type mismatch error on listview

    Quote Originally Posted by Pouncer
    yeah i used that code you gave, same prblem

    could it be something to do with listview box properties?

    i set the view property as lvwReport, any other properties?
    yes, have it in lvwReport and make sure that there are three columns set within the "columns headers" area of the properties window. my example works here so it should work there.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,364

    Re: type mismatch error on listview

    i have no idea why mine doesnt work in my project

    in my project i have form1 and form2

    i put the listview on form2 with your code and it gives me error..




    i made a fresh project, put a listview on form1 and it works

  10. #10
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    Re: type mismatch error on listview

    Quote Originally Posted by Pouncer
    i have no idea why mine doesnt work in my project

    in my project i have form1 and form2

    i put the listview on form2 with your code and it gives me error..




    i made a fresh project, put a listview on form1 and it works
    post the project and ill see whats going on

  11. #11
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: type mismatch error on listview

    Check your Components. Do you have both versions of the Windows Common Controls (5 and 6) in your project?

  12. #12
    New Member
    Join Date
    May 2020
    Posts
    6

    Lightbulb Re: type mismatch error on listview

    Quote Originally Posted by Pouncer View Post
    keeps giving me run time error 13

    VB Code:
    1. Private Sub Command1_Click()
    2.         Dim itm As ListItem
    3.         Set itm = ListView1.ListItems.Add(Text:="hi")
    4.         itm.SubItems(1) = "b"
    5.         itm.SubItems(2) = "a"
    6. End Sub

    any ideas guys whats wrong
    I am sure, your project does have both version of "Windows Common Controls" i.e. version 5 as well as 6. Replace all version 5 components with version 6, and remove version 5 component reference from project properties, and you are done. I always prefer to use MScomctl.ocx (version6) in place of Comctl32.ocx (version5).

  13. #13
    PowerPoster
    Join Date
    Nov 2017
    Posts
    3,138

    Re: type mismatch error on listview

    Quote Originally Posted by confeder8 View Post
    I am sure, your project does have both version of "Windows Common Controls" i.e. version 5 as well as 6. Replace all version 5 components with version 6, and remove version 5 component reference from project properties, and you are done. I always prefer to use MScomctl.ocx (version6) in place of Comctl32.ocx (version5).
    And so, after 17 years of doing nothing but mashing F5, Pouncer finally had his answer. He arose from his computer chair, the groove of his buttocks long since seared into the vinyl material, and walked to the bathroom. Looking at himself in the mirror, he wondered where the last 17 years had gone. His friends and family had ceased communications ages ago. "An answer is coming, I can feel it", he would tell them. For a time, they would just smile and attempt to change the subject. But eventually, the pain of seeing Pouncer so isolated from reality was too much for them to bear. And, if he was honest with himself, even he had begun to doubt if an answer would ever be forthcoming.

    But now, with answer in hand, he returned to his chair, and de-selected the superfluous component reference. He closed his eyes, said a small prayer, and pressed F5...
    Last edited by OptionBase1; Nov 28th, 2022 at 11:52 PM.

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