2010-05-19 4 views
0

I는 스플릿 쉼표로 구분 한 값을 바인딩리스트 박스, 등등이파싱 CSV 문자열과는 문자열 배열

str[0] ="210" 
str[1] ="abc.pdf" 
str[2] = "211" 
str[3] = "xyz.docx" 

과 같은. 0,2,4,6,8 [짝수 위치]에는 숫자가 있고 홀수 위치에는 문자열이 있습니다.

나는 클래스 Attachmodel

공공 클래스 AttachmentModel 내가 목록

를 사용하여 값을 설정하고 그리드에 바인딩 할 이상에서

Private _attachmentID As Integer = 0 
Private _attachmentPath As String = "" 

''' <summary> 
''' Get Set Attachment ID 
''' </summary> 
''' <value></value> 
''' <returns></returns> 
''' <remarks></remarks> 

Public 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 

최종 클래스

을 데

+0

무엇이 당신의 질문입니까? – volody

+0

감사합니다. 나는 어떤 방법 으로든 해결했습니다. 나는 내 대답을 올리고있다. –

답변

0

프로그래밍 방식으로 목록 상자에 CSV 문자열을 바인딩하려고합니다.

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