Hello
I have small problem with my lists where I am storing url links.
I add my links via textbox and button which shows on listbox but here small problem.
My link shows as "Collection" not as http://blablabla.com
I know that I make a mistake here.

urls.Add(AddLinksField.Text);
listBox1.Items.Add(urls);

But I forgot how should I add correctly these links to the list.

Next question is about removing positions from the list.
How should I read data from my list ?
I need to remove one position from list with "remove button"

Should I do this with "for loop" and indexing in lists ?

Thanks for help.

Once you have built your list you assign it as the datasource for the ListBox:

listBox1.DataSource = urls;

I don't know why but it adds only one(first) element to the listbox

Problem solved but I have different one with listbox and labels. I would like to click item on my listbox which shows details in labels for file. I am doing file downloader.
In these labels are connection speed, progress, file info and etc.

urls I add via textbox on listbox and to the list of urls.
I know that I can access data from listbox via listbox1.SelectedItem; but in this case it is not as easy as could be. Because I could add more than one link.

Here is some code

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        FileDownloader downloader = new FileDownloader();
        List<string> lst = new List<string>();
       
        //file size label of downloading data
        private void file_size(object sender, DownloadEventArgs e)
        {
            long fs = e.TotalFileSize/1024;
            string file_Size = fs.ToString();
            fileSize.Text = file_Size;
        }

        DownloadData f = new DownloadData();        

        //download button 
        private void downloadBtn_Click(object sender, EventArgs e)

        {

            int urls_count = lst.Count;
            downloader.AsyncDownload(lst);
            downloader.ProgressChanged += new DownloadProgressHandler(downloaded_data);
            downloader.ProgressChanged += new DownloadProgressHandler(file_size); 
            downloader.ProgressChanged += new DownloadProgressHandler(prcnt);
            downloader.ProgressChanged += new DownloadProgressHandler(remainingTime);
            downloader.ProgressChanged += new DownloadProgressHandler(spd);
            
            downloader.cn_band_lmt = 20480/urls_count;
            
        }

        private void downloaded_data(object sender, DownloadEventArgs e)
        {
            
            //downloaded data/actual file size
            long cfs = e.CurrentFileSize/1024;
            string downloaded_data = cfs.ToString();
            downloaded.Text = downloaded_data;
            
        }

        private void downloaded_Click(object sender, EventArgs e)
        {

        }
        //remaining time
        private void remainingTime(object sender, DownloadEventArgs e)
        {

            long cfs = e.TotalFileSize;
            long hfs = e.CurrentFileSize;
            long time = (cfs - hfs)/downloader.cn_band_lmt;
            timer.Text = time.ToString();
            
        }
        //bandwidth speed in kilo Bytes
        private void spd(object sender, DownloadEventArgs e)
        {
            long s = downloader.cn_band_lmt / 1024;
            speed.Text = s.ToString();
        }
        
        //download progress in percents
        private void prcnt(object sender, DownloadEventArgs e)
        {
            string prt = e.PercentDone.ToString();
            percent.Text = prt;
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

            // Get the currently selected item in the ListBox.
            string curItem = listBox1.SelectedItem.ToString();        
        }
        //cancel/pause downloading
        private void button1_Click(object sender, EventArgs e)
        {
            downloader.Cancel();
        }
        
        private void Add_Click(object sender, EventArgs e)
        {
            lst.Add(AddLinksField.Text);
            listBox1.Items.Add(AddLinksField.Text);            
        }
        
        private void Remove_Click(object sender, EventArgs e)
        {           
            lst.RemoveAt(listBox1.SelectedIndex);
            listBox1.Items.RemoveAt(listBox1.SelectedIndex);  
         }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

      

       
    }
}
This article has been dead for over six months. Start a new discussion instead.