Add List(Of String) to a Form’s Listbox

Asked

Viewed 235 times

0

Guys I have the following code in my DLL FTP to get the folders from the server:

Try



            Dim Serv As Net.FtpWebRequest = GetRequest(GetDirectory(directory))



            Serv.Method = Net.WebRequestMethods.Ftp.ListDirectory



            Dim reader As New StreamReader(Serv.GetResponse().GetResponseStream())
            Dim line = reader.ReadLine()
            Dim lines As New List(Of String)

            Do Until line Is Nothing
                lines.Add(line)
                line = reader.ReadLine()
            Loop


            Return lines.ToArray()
        Catch ex As Exception


        End Try

But whenever I try to list the directories in the list box of the form appears the following in LST System.String[]

1 answer

0


To add this information to Listbox utilize Datasource:

  Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim arquivo As New List(Of String)
        arquivo.Add("file1")
        arquivo.Add("file2")
        arquivo.Add("file3")

        Dim arrArqu = arquivo.ToArray()

        ListBox1.DataSource = arrArqu 'ou simplesmente arquivo
    End Sub
  • For the sake of learning better, could you explain to me about LST’s Datasouce?

  • A question! If I do so n have how I know how many files will be listed above your code list three files! is limited to having to program the amount, isn’t it a dynamic thing or I’m wrong?? I’m new in VB :D

  • According to MSDN the property DataSouce is a property of object implementing the interface IList, then, you can receive as value Litas or Arrays. The example above is just to illustrate, see that you are doing the same thing in your code Do Until dynamically. To know the quantity just use the property Count.

  • Thank you! I get it right.

  • Don’t forget to rate the answer. @Vyctorjunior ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.