Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I'm trying to add items to listbox from another class,the information pass to the funtion but the listbox dosen't seem to update. this is my code:

Main class (FORM) :
C#
public partial class Form1 : Form
    {
        
        public Form1()
        {
            InitializeComponent();
            
        }
// the function that updates the listbox
public void logURI(string OutputLog, string Information, string JOB)
        {
            try
            {
                listBox1.BeginUpdate();
                listBox1.Items.Insert(0, DateTime.Now.ToString() + " : " + JOB + " " + Information);
                listBox1.Items.Add("1");
                listBox1.EndUpdate();
                textBox1.Text = JOB;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

}


Second Class:

C#
 public class FtpFileSystemWatcherTS
    {
 Form1 logs = new Form1();
logs.logURI( "", "Found folder modefied today (" + FileName.TrimEnd(), ") ElectricaTS"); 


Can someone tell me wath I'm doing wrong ?
It's urgent!
Posted
Updated 6-Jan-12 3:45am
v2

1 solution

Dear Mitran,

As you are calling the function in Form1 in order to fill the list box but as the classes are different and the ListBox1 is located in one form hen you need to paas the Listbox as the parameter into the function in order to get it filled accordingly.

logs.logURI( "", "Found folder modefied today (" + FileName.TrimEnd(), ") ElectricaTS",listbox1);


I hope yo understand where you are going wrong.

Thanks
 
Share this answer
 
Comments
Mitran Stefanita Alexandru 6-Jan-12 5:34am    
Sincerely i understand the concep, but I can't put into practice, can you show me where to modify to work. pls

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