Solved

Using ListView

Posted on 2003-11-04
3
323 Views
Last Modified: 2011-04-14
(Relates to http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20787492.html )


How do I;

Add Items,
Read data individually from each field of a highlighted item (eg, read the data in column 4 of the currently selected item.),


Matt.
0
Comment
Question by:pyromatt
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 80 total points
Comment Utility
This is the way to add new items :

Dim Item As ListItem

Private Sub Command1_Click()
    Set Item = ListView1.ListItems.Add(, , "Item 1")
        Item.SubItems(1) = "Item 2"
        Item.SubItems(2) = "Item 3"
        Item.SubItems(3) = "Item 4"
End Sub

Private Sub Form_Load()

    ' This part you can set in the control properties also
        ListView1.View = lvwReport
        ListView1.ColumnHeaders.Add , , "One"
        ListView1.ColumnHeaders.Add , , "Two"
        ListView1.ColumnHeaders.Add , , "Three"
        ListView1.ColumnHeaders.Add , , "Four"
End Sub
0
 
LVL 14

Assisted Solution

by:aelatik
aelatik earned 80 total points
Comment Utility
This way you can read the selected item and subitems

    ' View the main item
        MsgBox ListView1.ListItems(ListView1.SelectedItem.Index)
    ' View the sub items
        MsgBox ListView1.ListItems(ListView1.SelectedItem.Index).ListSubItems(1)
        MsgBox ListView1.ListItems(ListView1.SelectedItem.Index).ListSubItems(2)
        MsgBox ListView1.ListItems(ListView1.SelectedItem.Index).ListSubItems(3)
0
 
LVL 49

Assisted Solution

by:Ryan Chong
Ryan Chong earned 20 total points
Comment Utility
and make sure the selecteditem is exist, or the code may rise an error, to ensure that, add this to check whether an item is selected or not:

..
'Quit if nothing is selected
If ListView1.SelectedItem Is Nothing Then Exit Sub
..

cheers
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now