Results 1 to 14 of 14
  1. #1
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted

    how i make a listbox hold things?

    ok if u didnt get by wat i ment by title i will explain xD

    im tryin to make a downloader type thing where i can put the downloadable files in a list box an have it download to where u save it to .. if u need to know lil bit more i try to explain thnks for the help
    Like so

    Last edited by pushdis15; 04-07-2011 at 04:10 AM.
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  2. #2
    Blubb1337's Avatar
    Join Date
    Sep 2009
    Gender
    male
    Location
    Germany
    Posts
    5,915
    Reputation
    161
    Thanks
    3,108
    And you want to save the information and reload it on startup or what?



  3. #3
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted
    Quote Originally Posted by Blubb1337 View Post
    And you want to save the information and reload it on startup or what?
    eh dont know how to explain i want it where i can save like alot of files to like a listbox where i can download the selected file @Blubb1337
    Last edited by pushdis15; 04-07-2011 at 04:14 AM.
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  4. #4
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    So you mean add a new link to the listbox? And then download the selected item from the listbox when the user presses the button?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #5
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted
    Quote Originally Posted by Jason View Post
    So you mean add a new link to the listbox? And then download the selected item from the listbox when the user presses the button?
    yea thats wat i mean @Jason
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  6. #6
    freedompeace's Avatar
    Join Date
    Jul 2010
    Gender
    female
    Posts
    3,033
    Reputation
    340
    Thanks
    2,792
    My Mood
    Sad
    Keep an independent list of stuff. In C#, you'd do it like so:

    Code:
    List<KeyValuePair<string, string>> items = new List<KeyValuePair<string, string>>();
    
    void PopulateItems()
    {
    foreach (KeyValuePair<string, string> item in items)
    ListBox1.Items.Add(item.Key);
    }
    
    void DownloadLinks()
    {
    foreach (KeyValuePair<string, string> item in items)
    (new WebClient()).DownloadFile("C:\Dest", item.Value); // example download code. replace with yours.
    }
    
    void DownloadSelectedLink()
    {
    foreach (KeyValuePair<string, string> item in items)
    if (ListBox1.SelectedText == item.Key)
    {
    (new WebClient()).DownloadFile("C:\Dest", item.Value); // example download code. replace with yours.
    break;
    }
    }
    
    void AddItem(string name, string URL)
    {
    items.Add(new KeyValuePair<string, string>(name, URL);
    }
    Sorry for the non-tabbing, did it on phone which has no tab key.


    edit: why am i spoonfeeding? :/
    Last edited by freedompeace; 04-07-2011 at 04:32 AM.

  7. #7
    justiman's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    47
    Reputation
    10
    Thanks
    4
    My Mood
    Fine
    if you want it to go to a download link then do this:

    Code:
    If Listbox1.SelectedItem = "put what item you want here" Then
    Try
        Process.Start("put the download link in here")
    Catch ex As Exception
    
    End Try
    End If
    that will work if you want it to take you to a download link

  8. #8
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted
    Quote Originally Posted by justiman View Post
    if you want it to go to a download link then do this:

    Code:
    If Listbox1.SelectedItem = "put what item you want here" Then
    Try
        Process.Start("put the download link in here")
    Catch ex As Exception
    
    End Try
    End If
    that will work if you want it to take you to a download link
    thnks but i want it where i can put the file i want in to the list box an have it directly downloaded from the list box to where ever they want to save that file to
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  9. #9
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Well, the listbox control doesn't have any features to allow you to have a displayed entry and a secondary value

    i.e your current listbox has

    SnowBird Webbrowser.zip

    But the link is obviously not that. The way I would handle this problem is to use a dictionary(Of String, String)

    Here's an example I wrote up quickly:

    First, the dictionary:
    [highlight=vb.net]
    Private linkDictionary As New Dictionary(Of String, String)
    [/highlight]

    Now declare the following methods:

    [highlight=vb.net]
    Private Sub updateListBox(ByVal lBox As ListBox, ByVal vals As Dictionary(Of String, String))
    lBox.Items.Clear()
    For Each kvp As KeyValuePair(Of String, String) In vals
    lBox.Items.Add(kvp.Key)
    Next
    End Sub

    Private Sub addToListBox(ByVal lBox As ListBox, ByVal display As String, ByVal link As String, ByRef vals As Dictionary(Of String, String))
    Try
    vals.Add(display, link)
    updateListBox(lBox, vals)
    Catch keyNfound As ArgumentException
    If keyNfound.Message.ToLower.Contains("already been added") Then MessageBox.Show("An item with that name is already in the listbox, please pick a unique name!", "Error: Duplicate entry", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End Sub

    Private Sub removeFromListBox(ByVal lBox As ListBox, ByVal curItem As String, ByRef vals As Dictionary(Of String, String))
    vals.Remove(curItem)
    updateListBox(lBox, vals)
    End Sub
    [/highlight]

    Now you just use those methods to do what they say:

    i.e to add an item to the listbox
    [highlight=vb.net]
    addToListBox(ListBox1, "Hello.zip", "https://www.example.com/files/hello.zip", linkDictionary)
    [/highlight]
    to remove an item from the listbox:
    [highlight=vb.net]
    removeFromListBox(ListBox1, ListBox1.SelectedItem.ToString, linkDictionary)
    [/highlight]
    to get the link associated with the current file:
    [highlight=vb.net]
    MessageBox.Show(getValue(ListBox1.SelectedItem.ToS tring, linkDictionary))
    [/highlight]

    So to download you would simply download the 'getValue' result.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  10. #10
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted
    Quote Originally Posted by Jason View Post
    Well, the listbox control doesn't have any features to allow you to have a displayed entry and a secondary value

    i.e your current listbox has

    SnowBird Webbrowser.zip

    But the link is obviously not that. The way I would handle this problem is to use a dictionary(Of String, String)

    Here's an example I wrote up quickly:

    First, the dictionary:
    [highlight=vb.net]
    Private linkDictionary As New Dictionary(Of String, String)
    [/highlight]

    Now declare the following methods:

    [highlight=vb.net]
    Private Sub updateListBox(ByVal lBox As ListBox, ByVal vals As Dictionary(Of String, String))
    lBox.Items.Clear()
    For Each kvp As KeyValuePair(Of String, String) In vals
    lBox.Items.Add(kvp.Key)
    Next
    End Sub

    Private Sub addToListBox(ByVal lBox As ListBox, ByVal display As String, ByVal link As String, ByRef vals As Dictionary(Of String, String))
    Try
    vals.Add(display, link)
    updateListBox(lBox, vals)
    Catch keyNfound As ArgumentException
    If keyNfound.Message.ToLower.Contains("already been added") Then MessageBox.Show("An item with that name is already in the listbox, please pick a unique name!", "Error: Duplicate entry", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
    End Sub

    Private Sub removeFromListBox(ByVal lBox As ListBox, ByVal curItem As String, ByRef vals As Dictionary(Of String, String))
    vals.Remove(curItem)
    updateListBox(lBox, vals)
    End Sub
    [/highlight]

    Now you just use those methods to do what they say:

    i.e to add an item to the listbox
    [highlight=vb.net]
    addToListBox(ListBox1, "Hello.zip", "https://www.example.com/files/hello.zip", linkDictionary)
    [/highlight]
    to remove an item from the listbox:
    [highlight=vb.net]
    removeFromListBox(ListBox1, ListBox1.SelectedItem.ToString, linkDictionary)
    [/highlight]
    to get the link associated with the current file:
    [highlight=vb.net]
    MessageBox.Show(getValue(ListBox1.SelectedItem.ToS tring, linkDictionary))
    [/highlight]

    So to download you would simply download the 'getValue' result.
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         
            Dim location As String
    
            Dim ofd As New SaveFileDialog
            ofd.Filter = "*.zip|*.zip|*.rar|*.rar"
            ofd.FileName = "Download"
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim lvi As New ListViewItem(ofd.FileName)
                location = (ofd.FileName)
                My.Computer.Network.DownloadFile(" " + ListBox1.SelectedItem.ToString, location)
    
            End If
    
            log1.Items.Add("Item " + ListBox1.SelectedItem.ToString + " Was Downloaded")
          end sub 
    end class
    thats what i did but it not showing up in the list box im trying to get it from my desktop as a location but it not working
    Last edited by pushdis15; 04-07-2011 at 04:55 AM.
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  11. #11
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Quote Originally Posted by pushdis15 View Post


    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
         
            Dim location As String
    
            Dim ofd As New SaveFileDialog
            ofd.Filter = "*.zip|*.zip|*.rar|*.rar"
            ofd.FileName = "Download"
            If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
                Dim lvi As New ListViewItem(ofd.FileName)
                location = (ofd.FileName)
                My.Computer.Network.DownloadFile(" " + ListBox1.SelectedItem.ToString, location)
    
            End If
    
            log1.Items.Add("Item " + ListBox1.SelectedItem.ToString + " Was Downloaded")
    thats what i did but it not showing up in the list box im trying to get it from my desktop as a location but it not working
    What even? you didn't use any of the code I posted, and I don't see a single ListBox.Items.Add method there so no shit there won't be anything in your textbox.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  12. #12
    pushdis15's Avatar
    Join Date
    Oct 2010
    Gender
    male
    Location
    spokane washington
    Posts
    923
    Reputation
    20
    Thanks
    170
    My Mood
    Twisted
    Quote Originally Posted by Jason View Post


    What even? you didn't use any of the code I posted, and I don't see a single ListBox.Items.Add method there so no shit there won't be anything in your textbox.
    thats not all my code thats the savefiledialog i pasted the wrong code D: aww forget bout it / close plz @Jason
    Last edited by pushdis15; 04-07-2011 at 05:12 AM.
    PlayStation ID:
    Boxing509

    Quote Originally Posted by pushdis15
    Women now have choices. They can be married, not married, have a job, not have a job, be married with children, unmarried with children. Men have the same choice we've always had: work, or prison.

  13. #13
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    5,055
    My Mood
    Cool
    I would of just put the link in tag ;P ..
    my blue file class held in tag for some time... never found the limit of it
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  14. #14
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,679
    My Mood
    Mellow
    Quote Originally Posted by topblast View Post
    I would of just put the link in tag ;P ..
    my blue file class held in tag for some time... never found the limit of it
    Read mai post. ListBox doesn't have a special object for it's items hence no Tag, Unless you code your own custom shit, you won't have a tag property.

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)