Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > ListView Add Item


Reply
 
Thread Tools Display Modes
  #1  
Old 01-05-2005, 08:23 AM
woody999 woody999 is offline
Centurion
 
Join Date: Mar 2004
Posts: 128
Talking ListView Add Item


Hi

No doubt a nice simple one for someone but I am trying to use the ListView to display a set of records.

Can somebody tell me how to add a value to the listview? I have a recordset and I asume I need to cycle through it adding each value to the listview - but how?

Cheers
Reply With Quote
  #2  
Old 01-05-2005, 09:10 AM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

One method is to iterate through the recordset and add an instance of a ListItem object to the ListItems collection of the ListView for each record. The value for the first column would be assigned to the Text argument when adding the ListItem and the values for the other columns would be added to the SubItems(n) collection. You will need to make sure that you have the ColumnHeaders defined in order to have each column available, and use the Report-View setting for the display.

Example:
Code:
Dim objListItem As ListItem Do While Not objRecordset.EOF Set objListItem = Me.ListView1.ListItems.Add(Text:=objRecordset.Fields(0).Value) objListItem.SubItems(1) = objRecordset.Fields(1).Value objListItem.SubItems(2) = objRecordset.Fields(2).Value ' etc. objRecordset.MoveNext Loop
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #3  
Old 01-05-2005, 09:46 AM
woody999 woody999 is offline
Centurion
 
Join Date: Mar 2004
Posts: 128
Default

Great that worked.

Is there a way to add an image to the 1st field in each row?
Reply With Quote
  #4  
Old 01-05-2005, 10:53 AM
00100b's Avatar
00100b 00100b is offline
Martian In Disguise

Retired Moderator
* Guru *
 
Join Date: May 2003
Location: Minneapolis, MN
Posts: 9,566
Default

Add a ImageList control to your form and populate with the images.

Bind the ImageList to the ListView control (Small ImageList property).

When adding the ListItem to the ListView, specify the Index value of the image in the ImageList in the SmallIcon argument of the Add method.
__________________
The only stupid question is the one that goes un-asked.
Reply With Quote
  #5  
Old 01-06-2005, 10:42 AM
woody999 woody999 is offline
Centurion
 
Join Date: Mar 2004
Posts: 128
Default

Cheers for that.

Everything works great now!
Reply With Quote
  #6  
Old 11-16-2005, 02:08 PM
rcorrea's Avatar
rcorrea rcorrea is offline
Centurion
 
Join Date: Aug 2003
Posts: 188
Default gosh

Been searching all morning how to get the dam imagelist icon to work. This is the best and simplest explanation, thank god for you!

Quote:
Originally Posted by 00100b
Add a ImageList control to your form and populate with the images.

Bind the ImageList to the ListView control (Small ImageList property).

When adding the ListItem to the ListView, specify the Index value of the image in the ImageList in the SmallIcon argument of the Add method.
__________________
Love thy neighbor, or he'll shoot you.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->