Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27411

How do I save selected listview items to user selected text file?

$
0
0
Hi,
This is a follow on from this post

http://www.vbforums.com/showthread.p...osen-directory

Thank you .paul and IanRyder for your help so far.

This is what I've got so far

Code:

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListView1.Columns.Add("FileName", 230, HorizontalAlignment.Left)
        ListView1.View = View.Details
        ListView1.CheckBoxes = True
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged
        If ListView1.CheckedItems.Count > 0 Then
            MsgBox(String.Join(Environment.NewLine, ListView1.CheckedItems.Cast(Of ListViewItem).Select(Function(lvi) lvi.Tag.ToString).ToArray))
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'declare new FolderBrowserDialog + set it's initial properties
        Dim fbd As New FolderBrowserDialog With { _
                .Description = "Select location of Gerber files", _
                .ShowNewFolderButton = False, _
                .SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)}

        'show the dialog + display the result in the listview unless cancelled
        If fbd.ShowDialog = DialogResult.OK Then
            ListView1.Items.AddRange(Array.ConvertAll(IO.Directory.GetFiles(fbd.SelectedPath), Function(f) New ListViewItem(IO.Path.GetFileName(f)) With {.Tag = f}))
        End If
    End Sub
End Class

Attachment 98269

Is there any way to hardcode the file extension (gb0,gb1,gb2 for example) into the type of file that can populate the listview?

Next I would like to save those filenames that are selected into a TXT file (one filename per line). The name of the text file is chosen by the user on pressing a button (however the file EXTENSION is hardcoded into the program). How can I do this? I've looked through the forum (and elsewhere)and there are no specific examples of this.
Any hints on doing this? Thanks again for any help.

David.
Attached Images
 

Viewing all articles
Browse latest Browse all 27411


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>