Solved

Using ListView

Posted on 2003-11-04
3
329 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 80 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 80 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 52

Assisted Solution

by:Ryan Chong
Ryan Chong earned 20 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month4 days, 1 hour left to enroll

630 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