Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ListView in VB.NET

Posted on 2003-11-07
5
Medium Priority
?
1,525 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 300 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

773 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