Jump to content

Listbox to Array


TS91
 Share

Recommended Posts

O truque está na linha em evidência.

        Dim LB1 As New ListBox
        Dim LB2 As New ListBox

        LB1.Items.Add("Olá")
        LB1.Items.Add("Olé")
        LB1.Items.Add("Olí")
        LB1.Items.Add("Oló")
        LB1.Items.Add("Olú")

        Dim TempArray() As String = Nothing

        For i As Integer = 0 To LB1.Items.Count - 1
            ReDim Preserve TempArray(i)
            TempArray(i) = LB1.Items(i)
        Next

        For Each S As String In TempArray
            LB2.Items.Add(S)
        Next

O estar noutro form, não implica nada muito mais especial.

Sérgio Ribeiro


"Great coders aren't born. They're compiled and released"
"Expert coders do not need a keyboard. They just throw magnets at the RAM chips"

Link to comment
Share on other sites

É ir acrescentando posições ao array, mas mantendo os valores que já estão guardados. Se só colocasses Redim os dados eram anteriormente guardados no array eram apagados.

"Nós somos o que fazemos repetidamente, a excelência não é um feito, e sim, um hábito."
Não respondo a questões por PM que possam ser colocadas no fórum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.