On a form there is a listbox containing serveral items (single column). These items are added to dynamically. No datasource is used.
I want to create a class that needs access to these items. I was thinking something in the line of:
Well, the list box items are not of the type List<string>, so that is why that will not work. The items are contained in a ListBox.ObjectCollection object ("Items"), so your parameter would need to be of the same type. However, I think this would be a pretty bad design choice here.
first I would ask; for what reason do you need access to these items on your second form? If you only need some of the data they contain, just pass that in. If you need to add or remove items, just make an event(s) in your second form class that can be handled by the main form. The secondary form can fire the events when data needs to be changed. This approach eliminates unnecessary coupling between the two classes.
Last edited by BigEd781; July 27th, 2009 at 01:10 AM.
Bookmarks