I have splitted comma separated values in an string array, something like this
str[0] ="210"
str[1] ="abc.pdf"
str[2] = "211"
str[3] = "xyz.docx"
and so on. Please note 0,2,4,6,8 [even positions] are having number and odd positions are having string.
I am having a class Attachmodel
Public Class AttachmentModel
Private _attachmentID As Integer = 0
Private _attachmentPath As String = ""
''' <summary>
''' Get Set Attachment ID
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Publ开发者_运维百科ic Property AttachmentID() As Integer
Get
Return _attachmentID
End Get
Set(ByVal value As Integer)
_attachmentID = value
End Set
End Property
''' <summary>
''' Get Set Attachment Path
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property AttachmentPath() As String
Get
Return _attachmentPath
End Get
Set(ByVal value As String)
_attachmentPath = value
End Set
End Property
End Class
In the above i want to set the values and bind it to the grid, using List
I want to bind CSV string with listbox programmatically
Private Sub BindAttachmentsToListBox(ByVal collectionData As String)
Dim arrayString As String()
Dim separator As String() = {",", "\n", " "}
Dim attachmentList As New List(Of AttachmentModel)
arrayString = collectionData.ToString().Split(separator, StringSplitOptions.RemoveEmptyEntries)
For i As Integer = 0 To arrayString.Length - 1
Dim attachments As New AttachmentModel()
attachments.AttachmentID = Integer.Parse(arrayString(i).ToString().Trim())
attachments.AttachmentPath = arrayString(i + 1).ToString.Trim()
attachmentList.Add(attachments)
i = i + 1
Next
lbAttachments.DataSource = attachmentList
lbAttachments.DisplayMember = "AttachmentPath"
lbAttachments.ValueMember = "AttachmentID"
End Sub
精彩评论