Hi Jim,
"Jim Heavey" <Ji*******@nosp am.com> wrote in message
news:Xn******** *************** **********@207. 46.248.16...
Thanks Lee for your comments....but
My form is a Class and I am creating an instance of that class, so what
are not all my public objects, contained within the form not available to me
if the form is in the same namespace and in the same project?
<snip>
A lengthy explanation (you've been warned). A line from your code:
Form frm = new frmGenericInput Dialog();
But you could also have coded:
Form frm = new Form();
or:
Form frm = new SomeOtherForm() ; // SomeOtherForm inherits Form
The point is, it is possible to point a variable of type Form (such as
frm, above) to any object instance that either is an instance of the Form
class or is an instance of a class that inherits from the Form class (as
does frmGenericInput Dialog). Now, if your variable "frm" points to anything
other than an instance of frmGenericInput Dialog, you know that this line:
frm.txtSkaterNa me.Text = item.SubItems[0].Text;
is just not going to work. Furthermore, there is no way for the compiler
to know at compile-time what specific type of object "frm" is going to
reference, but compiler *does* know that "frm" can only reference an object
that is a Form or inherits from Form. Therefore it makes sense that the
compiler will limit you to the operations (method calls, properties, ect.)
that are valid for a Form object only.
There are two ways around this. First, you could declare frm like this:
frmGenericInput Dialog frm = new frmGenericInput Dialog();
Now "frm" can only reference instances of frmGenericInput Dialog or
instances that inherit frmGenericInput Dialog. Thus any operation that is
valid for frmGenericInput Dialog will be valid for "frm".
The second way is to tell the compiler that even though "frm" is of type
Form, you know the object "frm" references is specifically of type
frmGenericInput Dialog. You do this with casting. You can read about casting
in the docs, but it can look like this:
Form frm = new frmGenericInput Dialog();
...
(frmGenericInpu tDialog)frm.txt SkaterName.Text =
item.SubItems[0].Text;
HTH.
Regards,
Dan