Activator Class : How to

  • Thread starter Thread starter Ian Semmel
  • Start date Start date
I

Ian Semmel

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 ?
 
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
 
Good

Michael said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top