In addition to soultion #1 by
OriginalGriff[
^] and solution #2 by
Richard MacCutchan[
^] ...
You should work on data instead of its string representation. It's called
Object Oriented Programming[
^].
Insert new class (name it:
MyData
) to your project and paste below code:
Public Class MyData
Private iID As Integer = 0
Private sName As String = String.Empty
Private sAddress As String = String.Empty
Public Sub New(ByVal sPipeLine As String)
Dim parts As String()= sPipeLine.Split(New String(){"|"}, StringSplitOptions.RemoveEmptyEntries)
iID = Int32.Parse(parts(0))
sName = parts(1)
sAddress = parts(2)
End Sub
Public Property ID As Integer
Get
Return iID
End Get
Set (value As Integer)
iID = value
End Set
End Property
Public Property Name As String
Get
Return sName
End Get
Set (value As String)
sName = value
End Set
End Property
Public Property Address As String
Get
Return sAddress
End Get
Set (value As String)
sAddress = value
End Set
End Property
Public Overrides Function ToString() As String
Return String.Format("{0}|{1}|[2}", iID, sName, sAddress)
End Function
Public Function ToArray() As String()
Return New String(){iID.ToString(), sName, sAddress}
End Function
End Class
How to use it?
Dim lines As String() = {"1|name|address", "2|name|address"}
Dim data As List(Of MyData) = lines _
.Select(Function(x) New MyData(x)) _
.ToList()
For Each md As MyData In data
Dim lvi As ListViewItem = New ListViewItem(md.ToArray())
Me.ListView1.Items.Add(lvi)
Next
For further details, please see:
ListViewItem Class (System.Windows.Forms)[
^]
ListViewItem Constructor (String[]) (System.Windows.Forms)[
^]
Object.ToString Method (System)[
^]