Add items to listbox from Class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a single form C# application called MainUI. On MainUI I have a
listbox that will log certain activity occuring in a seperate class file.
For example, the Class has a function that loops through a directory and
determines the filenames within the directory. Within this function I would
like the filenames to be sent to the listbox on MainUI. I can't seem to
figure this out. I have tried creating a public update method in MainUI to
update the listbox and call it from the seperate class (by creating a new
MainUI object in the seperate class). The code runs but the listbox doesn't
get updated. Please help...
 
JoshP,

The reason for this is that you create a new MainUI, which is a separate
instance from the one that created your class.

Rather, you should have Class fire an event after (or while) it is
looping through the directory. Then, have the MainUI form attach to the
event, and update the list box when the event is fired.
 
Thanks Nicholas-- could you provide a really quick generic example?

Nicholas Paldino said:
JoshP,

The reason for this is that you create a new MainUI, which is a separate
instance from the one that created your class.

Rather, you should have Class fire an event after (or while) it is
looping through the directory. Then, have the MainUI form attach to the
event, and update the list box when the event is fired.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

JoshP said:
I have a single form C# application called MainUI. On MainUI I have a
listbox that will log certain activity occuring in a seperate class file.
For example, the Class has a function that loops through a directory and
determines the filenames within the directory. Within this function I
would
like the filenames to be sent to the listbox on MainUI. I can't seem to
figure this out. I have tried creating a public update method in MainUI
to
update the listbox and call it from the seperate class (by creating a new
MainUI object in the seperate class). The code runs but the listbox
doesn't
get updated. Please help...
 
Back
Top