SolvedUseing Subitems in a Listview

Posts 1–7 of 7 · Page 1 of 1
Useing Subitems in a Listview
So I have list view columns that looks like this - |File Link|Download Directory|

How do I use the "Download Directory"(subitem) in the code to use it as an actual directory for a downloader?
Honestly I cant understand what is the issue here :s
I think he wants to get the filename of the URL from the "File Link" column and the directory at the "Download Directory" column so he can use it as an output file for the download link.

File Link: www.mpgh.net/dl/Files.rar
Save To: C:/Users/Anonymous/Desktop
Output File: C:/Users/Anonymoys/Desktop/Files.rar


This might be it..
Code:
    'TO GET THE OUTPUT FILENAME BY READING THE LINK ON THE FIRST COLUMN
    Public Function SaveAs(ByVal ListV As ListView, ByVal File As String) As String
        For i = 0 To ListV.Items.Count - 1 Step 1
            If ListV.Items(i).Text = File Then Return ListV.Items(i).SubItems(1).Text & "/" & GetFilename(File)
        Next
        Return ""
    End Function

    'TO GET THE OUTPUT FILENAME BY THE SELECTED ITEM (Only 1 item)
    Public Function SaveAs2(ByVal ListV As ListView) As String
        If ListV.SelectedItems.Count = 0 Then
            MsgBox("No selected files!", MsgBoxStyle.Critical, "ERROR")
        Else
            Return ListV.SelectedItems(0).SubItems(1).Text & "/" & GetFilename(ListV.SelectedItems(0).Text)
        End If
    End Function

    'Don't mind this. Its just needed for the codes above.
    Public Function GetFilename(ByVal File As String) As String
        For i As Integer = File.Length - 1 To 0 Step -1
            If File.Substring(i, 1) = "/" Then Return File.Substring((File.Substring(0, i) & "/").Length)
        Next
        Return ""
    End Function
How to use?
Code:
SaveAs(<<ListView>>,<<Filename>>)
SaveAs2(<<ListView>>)
Here's an example of a ListView with the sample usage
Filename Save To
www.mpgh.net/dl/Files.rar C:/Users/Anonymous/Desktop

Code:
My.Computer.Network.Download("www.mpgh.net/dl/Files.rar",SaveAs(ListView,"www.mpgh.net/dl/Files.rar")
'or
My.Computer.Network.Download("www.mpgh.net/dl/Files.rar",SaveAs2(ListView)
The Result should be "C:/Users/Anonymous/Desktop/Files.rar"
I hope this helps.
Quote Originally Posted by .Yuzuru View Post
I think he wants to get the filename of the URL from the "File Link" column and the directory at the "Download Directory" column so he can use it as an output file for the download link.

File Link: www.mpgh.net/dl/Files.rar
Save To: C:/Users/Anonymous/Desktop
Output File: C:/Users/Anonymoys/Desktop/Files.rar


This might be it..
Code:
    'TO GET THE OUTPUT FILENAME BY READING THE LINK ON THE FIRST COLUMN
    Public Function SaveAs(ByVal ListV As ListView, ByVal File As String) As String
        For i = 0 To ListV.Items.Count - 1 Step 1
            If ListV.Items(i).Text = File Then Return ListV.Items(i).SubItems(1).Text & "/" & GetFilename(File)
        Next
        Return ""
    End Function

    'TO GET THE OUTPUT FILENAME BY THE SELECTED ITEM (Only 1 item)
    Public Function SaveAs2(ByVal ListV As ListView) As String
        If ListV.SelectedItems.Count = 0 Then
            MsgBox("No selected files!", MsgBoxStyle.Critical, "ERROR")
        Else
            Return ListV.SelectedItems(0).SubItems(1).Text & "/" & GetFilename(ListV.SelectedItems(0).Text)
        End If
    End Function

    'Don't mind this. Its just needed for the codes above.
    Public Function GetFilename(ByVal File As String) As String
        For i As Integer = File.Length - 1 To 0 Step -1
            If File.Substring(i, 1) = "/" Then Return File.Substring((File.Substring(0, i) & "/").Length)
        Next
        Return ""
    End Function
How to use?
Code:
SaveAs(<<ListView>>,<<Filename>>)
SaveAs2(<<ListView>>)
Here's an example of a ListView with the sample usage
Filename Save To
www.mpgh.net/dl/Files.rar C:/Users/Anonymous/Desktop

Code:
My.Computer.Network.Download("www.mpgh.net/dl/Files.rar",SaveAs(ListView,"www.mpgh.net/dl/Files.rar")
'or
My.Computer.Network.Download("www.mpgh.net/dl/Files.rar",SaveAs2(ListView)
The Result should be "C:/Users/Anonymous/Desktop/Files.rar"
I hope this helps.
I forgot to mention that this can download multipal files, so I'm using a code like this
Code:
.LocalDirectory = openFolderDialog.SelectedPath
                For Each path As String In ListBox1.Items
                    .Files.Add(New FileDownloader.FileInfo(path))
and after, a separate download code.


---------- Post added at 04:33 PM ---------- Previous post was at 04:33 PM ----------

Quote Originally Posted by DawgiiStylz View Post
ListView1.Items.Item(0).SubItems.Item(0).Text = "First Row First Column"
ListView1.Items.Item(0).SubItems.Item(1).Text = "First Row Second Column"

For this to work, look at this.


The numbers on the left represents the item index. Thats where the 0 comes from in
"ListView1.Items.Item(0)"
and each item has its on subitems which are the columns in the same row and is also represented by index.
".SubItems.Item(0)" represents Column 1 and ".SubItems.Item(1)" is Column 2


You can also add in items by just,
Dim Item as new ListViewItem
Item.Text = "First Column"
Item.SubItems.Add("Second Column") 'You can also add fore, back colors and font
I know how to add it, I just need to know how to use it in the code.
ListView1.Items.Item(0).SubItems.Item(0).Text = "First Row First Column"
ListView1.Items.Item(0).SubItems.Item(1).Text = "First Row Second Column"

For this to work, look at this.


The numbers on the left represents the item index. Thats where the 0 comes from in
"ListView1.Items.Item(0)"
and each item has its on subitems which are the columns in the same row and is also represented by index.
".SubItems.Item(0)" represents Column 1 and ".SubItems.Item(1)" is Column 2


You can also add in items by just,
Dim Item as new ListViewItem
Item.Text = "First Column"
Item.SubItems.Add("Second Column") 'You can also add fore, back colors and font
Oh, I Was showing how the index of the listview worked with the code.
Quote Originally Posted by DawgiiStylz View Post
Oh, I Was showing how the index of the listview worked with the code.
Still useful though :P
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us