473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Activator Class : How to

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 ?
Aug 10 '06 #1
2 1851
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" <is***********@NOKUNKrocketcomp.com.auwrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
>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 ?

Aug 10 '06 #2
Good

Michael Klingensmith wrote:
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" <is***********@NOKUNKrocketcomp.com.auwrote in message
news:OH**************@TK2MSFTNGP04.phx.gbl...
>>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 ?


Aug 11 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: hazz | last post by:
this is a repost with more concise code (well, for me) and better questions (I hope....) . given the following two classes, my intent is to use either Activator.CreateInstance or InvokeMember pass...
3
by: System.Reflection Activator | last post by:
************************************** //Load the Assembly Assembly a = Assembly.LoadFrom(sAssembly); //Get Types so we can Identify the Interface. Type mytypes = a.GetTypes(); BindingFlags...
7
by: Ian Frawley | last post by:
Hi I have used the Activator class a number of times in my Windows apps and Windows Services and was thinking of using it again in one of my web services that I have been developing. I have been...
1
by: hazz | last post by:
this is a repost with a hopefully more clearly stated scenario and more concise questions at the end. given the following two classes, my intent is to use pass a token into the instantiated class...
3
by: bahadirarslan | last post by:
Hi All, I have a problem with Activator.CreateInstance method. I have got a class like this public class YaziYaz { public YaziYaz() { HttpContext.Current.Response.Write("Running");
1
by: Johnny R | last post by:
Hello, I'm loading a Class from Assemly DLL using Activator.CreateInstance. That loaded Class is executed in a worker Thread with no loop. What actually happends when class is loaded using...
0
by: Andy | last post by:
Hi, I have an internal class, which an internal constructor. In the same assembly as this class, I have a factory class which uses Activator.CreateInstance to create the instance. The code is...
1
by: Dan Dorey | last post by:
My goal is to pass in an assembly and have the method return an instance of any classes that inherit from the generic type T. My problem is that I'm unable to cast from the result of...
0
by: Jon Skeet [C# MVP] | last post by:
On Apr 11, 8:40 am, Andrew <And...@discussions.microsoft.comwrote: Okay, that means you've either not given the full classname (including namespace) or it's not in mscorlib or the currently...
0
by: =?Utf-8?B?QW5kcmV3?= | last post by:
Found it. string name = Properties.Settings.Default.ClassName.ToString(); //"myproject.myclass, myassembly" format. //name = "ABC.MyClass, Assem" ; Type t = Type.GetType(name); Object obj...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.