Hi Jim,
"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.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 frmGenericInputDialog();
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 frmGenericInputDialog). Now, if your variable "frm" points to anything
other than an instance of frmGenericInputDialog, you know that this line:
frm.txtSkaterName.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:
frmGenericInputDialog frm = new frmGenericInputDialog();
Now "frm" can only reference instances of frmGenericInputDialog or
instances that inherit frmGenericInputDialog. Thus any operation that is
valid for frmGenericInputDialog 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
frmGenericInputDialog. You do this with casting. You can read about casting
in the docs, but it can look like this:
Form frm = new frmGenericInputDialog();
...
(frmGenericInputDialog)frm.txtSkaterName.Text =
item.SubItems[0].Text;
HTH.
Regards,
Dan