tayleeming
asked on
ListView in VB.NET
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
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
also try:
ListView1.View = View.Details
ListView1.Columns.Add("COD E", 50, HorizontalAlignment.Center )
ListView1.Columns.Add("NAM E", 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")
ListView1.View = View.Details
ListView1.Columns.Add("COD
ListView1.Columns.Add("NAM
ListView1.Columns.Add("AGE
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")
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(strAnA rray(0))
lvItem.SubItems.Add(strAnA rray(1))
lvItem.SubItems.Add(strAnA rray(2))
' u'll want it to be some kind of a for loop.
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(strAnA
lvItem.SubItems.Add(strAnA
lvItem.SubItems.Add(strAnA
' u'll want it to be some kind of a for loop.
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")