Wrox Programmer Forums
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 29th, 2004, 10:13 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with Populating ListView

I'm trying to populate a ListView similar to the example on page 479 of "Beginning VB6 Database Programming" by John Connell, except I'm using ADO rather than DAO. I get the following runtime error at the "itemToAdd.SubItems(n)" lines:
Runtime error ‘380’: Invalid property value

My code extract is below. I’ve checked the Recordset is opened correctly and the fields are valid Strings – I’m using Biblio.mdb for testing. The ListView gets populated OK with the Title fields if I comment out the itemToAdd lines.

Any ideas?

While Not .EOF
            Set itemToAdd = lvProjects.ListItems.Add(, , !Title)
            If Not IsNull(![Year Published]) Then
                itemToAdd.SubItems(1) = CStr(![Year Published])
            End If
            If Not IsNull(!Description) Then
                itemToAdd.SubItems(2) = !Description
            End If
            .MoveNext
Wend
 
Old August 2nd, 2004, 04:50 AM
Authorized User
 
Join Date: Mar 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Do you have the subitems for the listview? In design time right click the list view ... You must have 3 fields in the example you gave.

Lucian Preda
[email protected]
 
Old August 2nd, 2004, 06:55 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by predal
 Do you have the subitems for the listview? In design time right click the list view ... You must have 3 fields in the example you gave.

Lucian Preda
[email protected]
The listview is being set up OK with 3 columns & column headers, if that's what you mean - or am I missing something else?
 
Old August 2nd, 2004, 08:19 AM
Registered User
 
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Brian_Leigh65
 
Quote:
quote:Originally posted by predal
Quote:
 Do you have the subitems for the listview? In design time right click the list view ... You must have 3 fields in the example you gave.

Lucian Preda
[email protected]
The listview is being set up OK with 3 columns & column headers, if that's what you mean - or am I missing something else?



Eureka, Lucian!! You gave me the clue as to what was wrong. I was setting up the columns (i.e subitems) in the form Initialize event. I moved the code inline to the same routine as the populate code & it now works!! Clearly, the subitems were being set up after I was trying to populate them. The hazards of event-driven programming!!

Many thanks,
Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Binding ComboBox inside ListView problem gunnjamie Windows Presentation Foundation 1 July 17th, 2008 02:13 PM
problem in populating datasheet ...... sms Access 4 June 1st, 2008 03:47 AM
Problem populating DataGridView MacDevv C# 2005 0 May 6th, 2008 08:50 AM
VB2005 Listview problem jgferguson Visual Basic 2005 Basics 0 February 27th, 2008 06:36 AM
problem selecting listview item method Visual C++ 0 July 7th, 2006 04:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.