Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
protected void Timer1_Tick1(object sender, EventArgs e)
       {
               string[] str;
               ftp = new FTPOperations();
               str = ftp.GetFileList("DCU/INST_VAL");
                   foreach (string value in str)
                   {
                       LstBox.Items.Add(value);

                   }
                   Label1.Text = DateTime.Now.ToShortTimeString();
       }

dear sir i am adding value to listbox for every 5 sec its updating and its adding previous values also..please tell me how to stop....please please help me
Posted

Call LstBox.Items.Clear(); before the foreach loop.
 
Share this answer
 
you can check and add items if not already added using listBox.Items.FindByValue but you have to loop though each and every item. easy way is fist clear items and add items again.

C#
protected void Timer1_Tick1(object sender, EventArgs e)
       {
               // clear items and add them
               LstBox.Items.Clear();
               string[] str;
               ftp = new FTPOperations();
               str = ftp.GetFileList("DCU/INST_VAL");
                   foreach (string value in str)
                   {
                       LstBox.Items.Add(value);
 
                   }
                   Label1.Text = DateTime.Now.ToShortTimeString();
       }
 
Share this answer
 
v2
C#
protected void Timer1_Tick1(object sender, EventArgs e)
       {
               // clear items and add them
               LstBox.Items.Clear();
               string[] str;
               ftp = new FTPOperations();
               str = ftp.GetFileList("DCU/INST_VAL");
                   foreach (string value in str)
                   {
                       LstBox.Items.Add(value);

                   }
                   Label1.Text = DateTime.Now.ToShortTimeString();
LstBox.Items.clear();

       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900