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

VS 2010 How do I select identical filenames in a listview by checking only 1 filename?

$
0
0
Hi,
I would like to be able to select 1 filename MANUALLY and the filenames that are identical are selected AUTOMATICALLY in the listview shown below.

Attachment 98395

Here is the code 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)}
        ' filter files by willcards (i.e. "*.ext")
        Dim extensions() As String = {"*.gb0", "*.gb1", "*.gb2", "*.drl"}

        '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
        If fbd.ShowDialog = DialogResult.OK Then
            Dim files() As String = FileIO.FileSystem.GetFiles(fbd.SelectedPath, FileIO.SearchOption.SearchTopLevelOnly, Extensions).ToArray
            ListView1.Items.AddRange(Array.ConvertAll(files, Function(f) New ListViewItem(IO.Path.GetFileName(f)) With {.Tag = f}))
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim strText As String = ""
        'Dim x As Integer
        Dim s As String = ""
        Dim file As System.IO.StreamWriter
        'Dim intC As Integer
        For Each checkedLVI As ListViewItem In ListView1.CheckedItems
            'Do what you want here
            'strText = s & "Checked Item " & (x + 1).ToString & " = " & ListView1.CheckedItems(x).ToString & ControlChars.CrLf
            strText += "Checked Item " & checkedLVI.Index & " = " & checkedLVI.Text & ControlChars.CrLf
        Next
        file = My.Computer.FileSystem.OpenTextFileWriter("MatrixMakerTest2_Output.txt", True)
        file.WriteLine(strText)
        file.Close()
        'For intC = 0 To ListView1.Items.Count - 1
        'strText &= CStr(CheckedListBox1.Items.Item(intC)) & vbCrLf

        'Next

    End Sub

End Class

I need to be able to do this as I may have to select upto 64 filenames (16 groups each with 4 files in each group) manually in the listview and being able to automate the selection would speed things up considerably. As the filename will be in groups of three or four with the same filename (but each one with a different file extension .gb0,.gb1,.gb2 and .drl) it makes sense to do this.
Could someone give me a hint on how I would do this? As always any and all help appreciated. Thanks.

David.
Attached Images
 

Viewing all articles
Browse latest Browse all 27333

Trending Articles



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