Connecting Tech Pros Worldwide Forums | Help | Site Map

Activator Class : How to

Ian Semmel
Guest
 
Posts: n/a
#1: Aug 10 '06
I may be way off track here but ...

I can do this :

DataGridViewColumn col = new DataGridViewCheckBoxColumn ();

but if I have this

Type t = typeof (DataGridViewCheckBoxColumn );

and I want something (like this which is wrong )

DataGridViewColumn col = Activator.CreateInstance ( t );

This doesn't work because you get the error 'Cannot implicitly convert object to
DataGridViewColumn ...'

What methods etc (if any) do I use to get around this without having to do an
explicit conversion ?

Michael Klingensmith
Guest
 
Posts: n/a
#2: Aug 10 '06

re: Activator Class : How to


Hi,

You almost had it. When the compiler says that it can't implicitly convert,
meaning that it is not an automatic conversion to the new type, you'll need
to add it yourself in the form of a cast...
....
DataGridViewColumn col = (DataGridViewColumn)Activator.CreateInstance ( t );

Michael Klingensmith
http://www.seeknsnatch.com

"Ian Semmel" <isemmelNOJUNK@NOKUNKrocketcomp.com.auwrote in message
news:OHl0O4MvGHA.4384@TK2MSFTNGP04.phx.gbl...
Quote:
>I may be way off track here but ...
>
I can do this :
>
DataGridViewColumn col = new DataGridViewCheckBoxColumn ();
>
but if I have this
>
Type t = typeof (DataGridViewCheckBoxColumn );
>
and I want something (like this which is wrong )
>
DataGridViewColumn col = Activator.CreateInstance ( t );
>
This doesn't work because you get the error 'Cannot implicitly convert
object to DataGridViewColumn ...'
>
What methods etc (if any) do I use to get around this without having to do
an explicit conversion ?

Ian Semmel
Guest
 
Posts: n/a
#3: Aug 11 '06

re: Activator Class : How to


Good

Michael Klingensmith wrote:
Quote:
Hi,
>
You almost had it. When the compiler says that it can't implicitly convert,
meaning that it is not an automatic conversion to the new type, you'll need
to add it yourself in the form of a cast...
...
DataGridViewColumn col = (DataGridViewColumn)Activator.CreateInstance ( t );
>
Michael Klingensmith
http://www.seeknsnatch.com
>
"Ian Semmel" <isemmelNOJUNK@NOKUNKrocketcomp.com.auwrote in message
news:OHl0O4MvGHA.4384@TK2MSFTNGP04.phx.gbl...
>
Quote:
>>I may be way off track here but ...
>>
>>I can do this :
>>
>>DataGridViewColumn col = new DataGridViewCheckBoxColumn ();
>>
>>but if I have this
>>
>>Type t = typeof (DataGridViewCheckBoxColumn );
>>
>>and I want something (like this which is wrong )
>>
>>DataGridViewColumn col = Activator.CreateInstance ( t );
>>
>>This doesn't work because you get the error 'Cannot implicitly convert
>>object to DataGridViewColumn ...'
>>
>>What methods etc (if any) do I use to get around this without having to do
>>an explicit conversion ?
>
>
>
Closed Thread