473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Add items to listbox from Class

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...
Sep 12 '07 #1
2 5708
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]
- mv*@spam.guard.caspershouse.com

"JoshP" <Jo***@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
>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...

Sep 12 '07 #2
Thanks Nicholas-- could you provide a really quick generic example?

"Nicholas Paldino [.NET/C# MVP]" wrote:
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]
- mv*@spam.guard.caspershouse.com

"JoshP" <Jo***@discussions.microsoft.comwrote in message
news:E1**********************************@microsof t.com...
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...


Sep 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David Ichilov | last post by:
I've class derived from "Object" class, with ToString() method overriden itc. , now i add object of this class to Windows.Forms.ListBox.Items collection, and it works fine, displaying what...
1
by: John R. | last post by:
How do I create an item for a listbox? I want to do something like this EXCEPT for a listbox: ListViewItem item = new ListViewItem(); item.Text = column.Name; int height = item.Bounds.Height;...
1
by: Claire | last post by:
As a Listbox.item, rather than using a string I'm using a ListItems object, overriding the ToString method When I add items to listbox.items, my strings are shown correctly. On the otherhand, when...
6
by: Valerian John | last post by:
I have a ListBox webcontrol on an aspx page. Items are added to the ListBox using client-side code. However, when the page is posted back the items are missing/not available. (It is like the...
3
by: Joey | last post by:
Hi, I'm trying to add a default item to my listbox but when I do it tells me that it's not defined, could someone tell me the syntax I need to use to get the listbox control to display a default...
4
by: Robin Tucker | last post by:
How do I sort the items in a list box? I am using a class derived from IComparer to sort items on columns in a ListView, but the ListBox doesn't support this kind of facility. The "items" in my...
2
by: Joe Fallon | last post by:
I have 2 listboxes on a Web Form. As I move an item from 1 to the other it shows up at the end of the list. How can I sort the list that just got the new item added to it so it is in alphabetical...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
1
by: cowznofsky | last post by:
I was databinding to a combobox and supplying both a DisplayMember and a ValueMember, so that each item. Now I've decided against databinding, and will populate it by going through a datatable....
1
by: Refugnic | last post by:
I tried to fill a ListBox with a DataSource pointing to an ArrayList. It all works fine...up to one point. The ArrayList is dynamic, which means the contents of it change, during the course of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.