Solved

Using ListView

Posted on 2003-11-04
3
324 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
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 49

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Input past end of file vbs script 9 81
message box in access 4 41
SLMGR Switches Are Not Working On KMS Host 3 67
Spell Check in VB6 13 96
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

911 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

17 Experts available now in Live!

Get 1:1 Help Now