Friday, April 29, 2011

Save ListBox Using SaveDialog

To save ListBox items using the SaveDialog you should write the code bellow:

        Dim dialog As New SaveFileDialog
        dialog.Filter = "Text files (*.txt)|*.txt"
        dialog.FilterIndex = 2

        If dialog.ShowDialog() = DialogResult.OK Then
            Dim output As New IO.StreamWriter(dialog.FileName)

            For Each item As Object In ListBox1.Items
                output.WriteLine(ListBox1.GetItemText(item))
            Next item

            output.Close()
        End If

No comments:

Post a Comment

There was an error in this gadget