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

x
?
Solved

ListView in VB.NET

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

Basic Security of Your VPC

So, you’ve got this shiny new VPC and a fancy new application configured on your EC2 servers ready to go. This application is only accessible from your computer, which is great for security, but you need your users to be able to access it! So, what’s the easiest way to do this?

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

688 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