Solved

ListView in VB.NET

Posted on 2003-11-07
5
1,499 Views
Last Modified: 2012-06-27
hi,
   
  let say i have some data as below

  CODE          NAME                 AGE
  ====         ====                ===
  001             ABC                   10
  002             DEF                   12
  003             XYZ                     8
   

  can anyone tell me how to load this data into a listview in VB.NET
0
Comment
Question by:tayleeming
5 Comments
 
LVL 6

Expert Comment

by:DaniPro
ID: 9700204
You can use this simple code:
        ListBox1.Items.Add("001" + Chr(9) + "ABC" + Chr(9) + "10")
        ListBox1.Items.Add("002" + Chr(9) + "DEF" + Chr(9) + "12")
        ListBox1.Items.Add("003" + Chr(9) + "XYZ" + Chr(9) + "8")
0
 
LVL 6

Expert Comment

by:DaniPro
ID: 9700245
oops you have asked from ListView .... you can use the same code, but please, tell me if you must create a subitem .... the code is different
0
 
LVL 9

Accepted Solution

by:
tinchos earned 75 total points
ID: 9700688
Try with these


       Dim listViewItem1 As New ListViewItem(New String() {"Banana", "a", "b", "c"} )
       Dim listViewItem2 As New ListViewItem(New String() {"Cherry", "v", "g", "t"} )
       Dim listViewItem3 As New ListViewItem(New String() {"Apple", "h", "j", "n"} )

       ListBox1.Items.Add( listViewItem1 )
       ListBox1.Items.Add( listViewItem2 )
       ListBox1.Items.Add( listViewItem3 )

Hope that helped.......

Tincho
0
 
LVL 3

Expert Comment

by:the-edge
ID: 9700790
also try:

        ListView1.View = View.Details
        ListView1.Columns.Add("CODE", 50, HorizontalAlignment.Center)
        ListView1.Columns.Add("NAME", 50, HorizontalAlignment.Center)
        ListView1.Columns.Add("AGE", 50, HorizontalAlignment.Center)

        Dim lvItem As ListViewItem
        lvItem = ListView1.Items.Add("001")
        lvItem.SubItems.Add("ABC")
        lvItem.SubItems.Add("10")

        lvItem = ListView1.Items.Add("002")
        lvItem.SubItems.Add("DEF")
        lvItem.SubItems.Add("12")

        lvItem = ListView1.Items.Add("003")
        lvItem.SubItems.Add("XYZ")
        lvItem.SubItems.Add("8")
0
 

Expert Comment

by:suvlaki
ID: 10041382
if u're reading from a text file or a long string with all those above data as u've mentioned above, u may want to arrange it in a specific order with some kind of delimiter value. and then use a split funciton  then do those listview.add  things. (note that I'll use part of the code given by 'the-edge')
i.e.
     ' data
 ' 000||abc||10

  dim strReadInString = "000||abc||10"  ' u'll have to change the value to what ever data you're extracting
  dim strAnArray() as String

strAnArray = split(readInString,"||") ' the function to split it and insert it to what ever array.

         Dim lvItem As ListViewItem
        lvItem = ListView1.Items.Add(strAnArray(0))
        lvItem.SubItems.Add(strAnArray(1))
        lvItem.SubItems.Add(strAnArray(2))
 ' u'll want it to be some kind of a for loop.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

22 Experts available now in Live!

Get 1:1 Help Now