Solved

ListView in VB.NET

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VS 2017 18 193
Can Selenium do Load Testing? 2 61
unable to isntall .net framework 3.5 19 38
Binding a GridView in ASP.NET(VB) using Using statements 6 18
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

751 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