Cycling through all GUI Objects within a form
-
Then you will have to use reflection to determine if you need to recurse into a Controls collection or an Items collection.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
I Have just recently heard about reflection and I'm quite not familiar with the subject. So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection. ( I'm a litle busy the next days any I need this job to be done as quickly as possible ). Thanks.
-
Then you will have to use reflection to determine if you need to recurse into a Controls collection or an Items collection.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Iterate like people have said, but check the type of the object, and run a separate peice of code to get its items collection, or its child controls etc. Whatever you do, im pretty sure there isn't some simple function you can use, its gonna take quite the chunk of code, and your probably gonna have to write it all yourself.
you go to hell.............
-
Don't you think, that this would bring a lot of useless matches (ListBox.Items). I think it would be easier to check out how many control classes don't match "Controls", and do a typecheck ("as") at them!
All the best, Martin
Martin# wrote:
Don't you think, that this would bring a lot of useless matches (ListBox.Items).
Since I don't know what the overall purpose is I can't say if that would bring lots of useless matches or not. It might do. It might not.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Then you will have to use reflection to determine if you need to recurse into a Controls collection or an Items collection.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
I wouldn't use reflection. I'd just test if the current control is of a type with a property Controls or whether it is of for example type ToolStrip: Or the make the code more readable, introduce several overloaded methods that take the different types as a parameter (one overload for control, one for toolstrip, ....) And call them recursively.
-^-^-^-^-^- no risk no funk ................... please vote ------>
-
Do not forget to check the HasChildren property. Speeds things up.
-^-^-^-^-^- no risk no funk ................... please vote ------>
That may depend on how the enumeration is implemented.
-
you go to hell.............
Whould you mind explaining yourself?? Undefeated's explanation and suggestion is perfectly valid.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Martin# wrote:
Don't you think, that this would bring a lot of useless matches (ListBox.Items).
Since I don't know what the overall purpose is I can't say if that would bring lots of useless matches or not. It might do. It might not.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
Whould you mind explaining yourself?? Undefeated's explanation and suggestion is perfectly valid.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
I Have just recently heard about reflection and I'm quite not familiar with the subject. So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection. ( I'm a litle busy the next days any I need this job to be done as quickly as possible ). Thanks.
-
I Have just recently heard about reflection and I'm quite not familiar with the subject. So... can you please hand me a little piece of code to show how can this be done so I will not have to read all about reflection. ( I'm a litle busy the next days any I need this job to be done as quickly as possible ). Thanks.
You can ask every object for its type with
.GetType()
. You get back aType
object. It has methods on it such asGetMethod
,GetProperty
and so on. You can get information from the objects those methods returnMethodInfo
orPropertyInfo
and so on. If you find the one you want you can thenInvoke
it. Most of this should make enough sense through intellisense. You may have to look up some stuff in the documentation though. It really is worth reading up on so you have a better understanding of the environment in which you are working.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website
-
You can ask every object for its type with
.GetType()
. You get back aType
object. It has methods on it such asGetMethod
,GetProperty
and so on. You can get information from the objects those methods returnMethodInfo
orPropertyInfo
and so on. If you find the one you want you can thenInvoke
it. Most of this should make enough sense through intellisense. You may have to look up some stuff in the documentation though. It really is worth reading up on so you have a better understanding of the environment in which you are working.
Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website