+ Reply to Thread
Results 1 to 14 of 14

Populating ListView control

  1. #1
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Populating ListView control

    I'm trying to populate a listview control, i have an advanced search performed on a 20000 item excel list (using vba) and the results are sent to sheet1, i want to have this range viewed in a listview control (rather than listbox, because people can change the colmun widths dynamically). To populate the listview box i have this:


    Please Login or Register  to view this content.
    But i get 'object doesnt support this method or property' at the do until line, i cant work out why..

    Can anybody help, or is there a better method to do this?

    Thanks in advance,

    Jack

  2. #2
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,330

    Re: Populating ListView control

    Hi jberr
    A good article here
    http://www.dailydoseofexcel.com/arch...2/26/listview/
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

  3. #3
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Populating ListView control

    worksheet object does not have an activecell object.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  4. #4
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    Thanks for the quick response guys,

    Pike, I gave the article a look at, it more focused on populating with userform data rather than an excel sheet, thankyou though!

    Andy, il give your code a go and get back to you with some feedback.. thankyou also.

    Cheers
    Jack

  5. #5
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Populating ListView control

    dam i must be slow,
    Please Login or Register  to view this content.
    Look like you are in good hands, ill bow out.. all the best


  6. #6
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    hi guys,

    again, thakyou for helping so quickly!

    Andy, your code only runs when remove:

    Please Login or Register  to view this content.
    else i get an object required error, when i remove it i get the listview box to populate but you cannot see an item in the list? i can see the scroll bar moving, but nothing in the box.. how strange.. what am i doing wrong?

    D_rennie, your code works however i get all the items from my first column set up in a grid view kind of thing, rather than list.. how do i stop this

    You would think trying to show a range in an unedittable form, with adjustable columns (autofit) would be simple..

    I have about 25 different columns of info for each row. I made it work with a listbox fine, however, because the order of the colmuns can change, setting fixed columns width wasnt an option. Im getting lost!

    thanks for all your help,

    Jack

  7. #7
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    I just got D_rennie's working, i didnt quite understand all the properties for listview!

    Is they any way of not having to type the column titles withing the code,. instead just take them from row A on sheet1? It means that when people come an edit the data (i.e. the column headings) the tool keep its self up to date..

    Is it possible to add column of info if row A has text in, i.e. dynamic range? Keep looking along until theres no more data to be put into the table.. its means that if people add extra columns in the future then, again, the tool keeps it self up to date? i managed it with the listbox.. but listview is entirely different..

    Thankyou so much in advance... i coudlnt of done this alone!

    Jack

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Populating ListView control

    try this

    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    Andy,

    That is amazing! I've been trying all day to achieve exactly that! thankyou!

    Couple of things though, can i autosize columns at userform_initialisation? And is there a method of removing columns if there is nothing inside of them exept the header?

    The database is a list of standard nuts, bolts and washers etc. When I search for washers i still have the column 'thread length' on display but with no data within it. Vice versa with a bolt search, i have 'thickness', reffering to washers, but with no infomation within it. Is there a way of hiding these columns if theres no data filling them?

    Thankyou so much for all of this, i was totally lost.. pulling my hair out all day over this and you saved me!

    Cheers
    Jack

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Populating ListView control

    this revision will use the columns width as a value to set the listview columnwidth.
    In the example I posted if you clear any of the columns, except the first, this will ignore that column.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    Andy,

    You are actually a genius, how do you know his stuff? its incredible!
    Thankyou so much again.. I've actually learnt a huge amount by studying your code. That worked a treat.

    Is there any way to format the first column, i.e. the first column is numerical but is formatted to 6 digits (padded with zeros) 1 is 000001 etc. Is there a way of making the numbers appear like this in the listview column?

    Thanks again
    Jack

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,434

    Re: Populating ListView control

    how do you know his stuff?
    The hardway. Lots of reading, learning, trying and experimenting.

    you can use the cells numberformat to format the value
    Please Login or Register  to view this content.
    Or you code just use the .Text property rather than .Value

  13. #13
    Registered User
    Join Date
    03-10-2010
    Location
    Cornwall, England
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Populating ListView control

    Works like a charm, thankyou Andy!

  14. #14
    Registered User
    Join Date
    07-16-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Populating ListView control

    Hi
    How to change the listView only show The Data from A16:I48
    And the header start from column A to I

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1