iText - How to Use "For Each" in VB.NET

Asked

Viewed 52 times

1

I’m trying to use the "For Each" to generate multiple PDF’s, such as a Word Direct Mail. My idea is to select several names from Listbox and generate Pdfs with selected items. My code is like this:

Dim listarNomes As String = ListBox1.GetItemText(ListBox1.SelectedItem)

        Dim data As String() = {listarNomes}

        For i As Integer = 0 To data.Length - 1
            doc.NewPage()
            doc.Add(gif)
            doc.Add(New Paragraph(" "))
            doc.Add(New Paragraph(data(i), fonte1))

        Next

Even when I select several names from Listbox, only generates a page with only one name. My Listbox uses Data Association Entries.

1 answer

1


Make a For Each inside ListBox.SelectedItems:

For Each listaItem In ListBox1.SelectedItems
    Dim listarNomes As String = ListBox1.GetItemText(listaItem)

    Dim data As String() = {listarNomes}

    For i As Integer = 0 To data.Length - 1
        doc.NewPage()
        doc.Add(gif)
        doc.Add(New Paragraph(" "))
        doc.Add(New Paragraph(data(i), fonte1))
    Next
Next

This way you will go through all the selected items in your ListBox, once it is enabled to select multiple items.

Browser other questions tagged

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