Solved

ListView in VB.NET

Posted on 2003-11-07
5
1,514 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 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

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

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

628 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