Joey,
I'd suggest a different route.
I'd have a backend object, used to hold items. And implement the Singleton
design pattern.
If you go to my blog:
http://sholliday.spaces.msn.com/
10/24/2005
I have a "Web Session Object Holder".
You can read about the concept there.
Here is a "winforms" version of that same code:
You can find the code to use it at the blog.
But basically, .. like in your Form2 ... cmdClose button, you can do
something like this:
MemoryDataStore mds = MemoryDataStore .GetInstance();
object testO = new object();
mds.Add ("mykeyname" , testO );
Ok.. then after you get back from the form2 you do this
MemoryDataStore mds = MemoryDataStore .GetInstance();
object oFromStore = mds.Remove("myk eyname") as object;
if(null!=oFromS tore)
{
//do something with o//
}
of course, change "object" to whatever object you're interested in.
Put your "mykeyname" in a constant somewhere..... to be consistent.
The object was written with 1.1 in mind. I haven't thought about rewriting
it with 2.0 Generics in mind.
public class MemoryDataStore //: IDataStore
{
private static MemoryDataStore singletonInstan ce = null;
private HybridDictionar y m_memoryStore = null;
//private Hashtable m_memoryStore = null;
private MemoryDataStore ( )
{
m_memoryStore = new HybridDictionar y(); // Implements IDictionary by
using a ListDictionary while the collection is small, and then switching to
a Hashtable when the collection gets large.
//m_memoryStore = new Hashtable(); // Implements IDictionary by using a
ListDictionary while the collection is small, and then switching to a
Hashtable when the collection gets large.
}
public static MemoryDataStore GetInstance( )
{
if( null == singletonInstan ce )
{
singletonInstan ce = new MemoryDataStore ( );
}
return singletonInstan ce;
}
public void Clear( )
{
m_memoryStore.C lear( );
}
public void Add( string key, object value )
{
if( m_memoryStore.C ontains( key ) )
{
m_memoryStore.R emove( key );
}
m_memoryStore.A dd( key, value );
}
public object Remove( string key )
{
// see
http://java.sun.com/j2se/1.4.2/docs/...va.lang.Object)
// for java method, which returns the object you removed, in case
// you want to do something with it
object returnObject = null;
if (null != this.m_memorySt ore)
{
if( m_memoryStore.C ontains( key ) )
{
returnObject = this.m_memorySt ore[key];
m_memoryStore.R emove( key );
}
}
return returnObject;
}
public object this[ string key ]
{
get
{
if( null != m_memoryStore[ key ] )
{
return m_memoryStore[ key ];
}
return null;
}
}
public int Size
{
get
{
if( null != m_memoryStore )
{
return m_memoryStore.C ount ;
}
return 0;
}
}
}
<jo*********@to pscene.comwrote in message
news:11******** *************@7 5g2000cwc.googl egroups.com...
Hello,
I have a windows forms application (VS2005) where I need to do the
following...
1. Startup with a main form.
2. Have the user to select a file and then bring up a second form
modally (Form1.ShowDial og()) so that the user can make custom
selections.
3. I can store the selections from the second form in many different
ways, but I have to get them back to the main form once the modal form
is closed. The selections are column header names, and right now I am
choosing to store them in a Generic List<string>.
I am doing fine so far, but now I need to figure out the best way to
get the selections back to the main form, once the user clicks
"Continue" and I call this.Close() on the second form.
I thought about creating the list and then passing a reference to the
modal form's constructor: "ref List<stringMyLi st". But this doesn't
work because the list is not scoped outside of the modal form's
constructor. And so I cannot interact with it when other events occur
on the form, like for example, a button click.
Another way would be create and modify the list within the second form
and then simply "return" it, but as far as I know one cannot do that
when using forms (would not be a problem with plain old functions).
There is not a return(MyList) that will work when closing a form,
right?
What would be a good way to tackle this?