Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using ListView

Posted on 2003-11-04
3
Medium Priority
?
331 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
aelatik earned 320 total points
ID: 9680074
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 320 total points
ID: 9680098
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 53

Assisted Solution

by:Ryan Chong
Ryan Chong earned 80 total points
ID: 9685093
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

661 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