473,382 Members | 1,657 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,382 software developers and data experts.

Control Property

Hi,

I'm creating a function that looks at every control on a form and changes a
property if it exists. I've coded so far to find every control, including
nested - but how do I determin if a property exists first so that it can be
changed. e.g change the TEXT of every control (but not all controls may have
a property of TEXT).

Many Thanks.

Merlin.
Nov 20 '05 #1
5 1264
Use reflection to examine the object and get it's properties. Then
manipulate the property via the property decriptor.

dim pdc as
PropertyDescriptorCollection=TypeDescriptor.GetPro perties(myControl)
dim pd as PropertyDescriptor = pdc.Find("Location",false)
if not pd is nothing then
'do something to the property here...
end if
--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Merlin" <iM*****@hotmail.com> wrote in message
news:bm**********@sparta.btinternet.com...
Hi,

I'm creating a function that looks at every control on a form and changes a property if it exists. I've coded so far to find every control, including
nested - but how do I determin if a property exists first so that it can be changed. e.g change the TEXT of every control (but not all controls may have a property of TEXT).

Many Thanks.

Merlin.

Nov 20 '05 #2
try the following code samples

For Each c As Control In Me.Controls
If Not (c.GetType().GetProperty("YourAttribute") Is Nothing)
Then

' add your set property code here

End If
Next

Hope It Helps!

Microsoft .NET MVP
Shanghai China

--
Microsoft .NET MVP
"Merlin" <iM*****@hotmail.com> wrote in message
news:bm**********@sparta.btinternet.com...
Hi,

I'm creating a function that looks at every control on a form and changes a property if it exists. I've coded so far to find every control, including
nested - but how do I determin if a property exists first so that it can be changed. e.g change the TEXT of every control (but not all controls may have a property of TEXT).

Many Thanks.

Merlin.

Nov 20 '05 #3
Thanks Bob

That did the trick!

Merlin
"Bob Powell [MVP]" <bob@_spamkiller_bobpowell.net> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Use reflection to examine the object and get it's properties. Then
manipulate the property via the property decriptor.

dim pdc as
PropertyDescriptorCollection=TypeDescriptor.GetPro perties(myControl)
dim pd as PropertyDescriptor = pdc.Find("Location",false)
if not pd is nothing then
'do something to the property here...
end if
--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

"Merlin" <iM*****@hotmail.com> wrote in message
news:bm**********@sparta.btinternet.com...
Hi,

I'm creating a function that looks at every control on a form and changes
a
property if it exists. I've coded so far to find every control,

including nested - but how do I determin if a property exists first so that it can

be
changed. e.g change the TEXT of every control (but not all controls may

have
a property of TEXT).

Many Thanks.

Merlin.


Nov 20 '05 #4
"Merlin" <iM*****@hotmail.com> wrote in message
news:bm**********@sparta.btinternet.com...
.. . .
I'm creating a function that looks at every control on a form and
changes a property if it exists. .. . . how do I determin if a property exists first so that it can be
changed.


There's probably some clever way using Reflection, but why bother?
Try and set the property, Catch the Exception thrown if the property
doesn't exist and do precisely nothing about it, as in

For Each eControl as Object in Me.Controls
Try
eControl.Checked = True
Catch MissingMemberException
' Do Nothing
End Try
Next

Of course
HTH,
Phill W.
Nov 20 '05 #5
If he has Option Strict turned on (which is a very good idea), late binding
won't be allowed and your code won't work.
"Phill. W" <P.A.Ward@o-p-e-n-.-a-c-.-u-k> wrote in message
news:bm**********@yarrow.open.ac.uk...
"Merlin" <iM*****@hotmail.com> wrote in message
news:bm**********@sparta.btinternet.com...
. . .
I'm creating a function that looks at every control on a form and
changes a property if it exists.

. . .
how do I determin if a property exists first so that it can be
changed.


There's probably some clever way using Reflection, but why bother?
Try and set the property, Catch the Exception thrown if the property
doesn't exist and do precisely nothing about it, as in

For Each eControl as Object in Me.Controls
Try
eControl.Checked = True
Catch MissingMemberException
' Do Nothing
End Try
Next

Of course
HTH,
Phill W.

Nov 20 '05 #6

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

Similar topics

2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: news.microsoft.com | last post by:
I have a user control with four option buttons depending which option button is pressed I store a score into session object. On the load event of a control the session object is set to 0. There is...
1
by: ANDRES BECERRA | last post by:
Herfried K. Wagner was kind enough to point me to the PropertyGrid control http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwindowsformspropertygridclasstopic.asp I have found a few...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
by: John Keenan | last post by:
I have a user control with 2 buttons on it & 1 label.... as each button is pressed, they set a member variable within the class and sets the label test. I also have a get/set property for the...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
5
by: Richard Brown | last post by:
Ok, I've been looking through the .NET SDK docs and stuff. I'm wondering if you can provide a control extender that does generic validation or functionality just by dropping it on the form. For...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
2
by: Mike | last post by:
Hi, I am strugling with a simple problem which I can't seem to resolve. I have an asp.net page which contains a server-control (flytreeview, which is a kind of a tree to be exact). The tree is...
3
by: shapper | last post by:
Hello, How can I send a control to a class as a property? I don't know which control it would be. It could be a panel, a label .... Thanks, Miguel
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.