473,398 Members | 2,404 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,398 software developers and data experts.

How to get properties of a control

Hi

I am using the below code to get properties and then sub properties on an
object;

Dim Prop As PropertyDescriptor
Dim Props As PropertyDescriptorCollection

Props = TypeDescriptor.GetProperties(Ctrl)

For Each Prop In Props
Dim PropObject As Object = Prop.GetValue(Ctrl)
Dim converter As TypeConverter = TypeDescriptor.GetConverter(PropObject)
...
Next

Unfortunately the PropObject comes out as nothing for Ctrl =
{System.Windows.Forms.BindingNavigator}on line Dim PropObject As Object =
Prop.GetValue(Ctrl) and this gives 'System.ArgumentException was unhandled'
error on the line Dim converter As TypeConverter =
TypeDescriptor.GetConverter(PropObject). How can I get round this problem?
The value of prop when this error came as per watch is given below.

Thanks

Regards

- Prop {System.ComponentModel.ReflectPropertyDescriptor}
System.ComponentModel.PropertyDescriptor
+ System.ComponentModel.ReflectPropertyDescriptor
{System.ComponentModel.ReflectPropertyDescriptor}
System.ComponentModel.ReflectPropertyDescriptor
+ Attributes {System.ComponentModel.AttributeCollection}
System.ComponentModel.AttributeCollection
Category "Behavior" String
+ ComponentType {Name = "Control" FullName =
"System.Windows.Forms.Control"} System.Type
+ Converter {System.ComponentModel.ComponentConverter}
System.ComponentModel.TypeConverter
Description "The shortcut menu to display when the user right-clicks the
control." String
DesignTimeOnly False Boolean
DisplayName "ContextMenuStrip" String
IsBrowsable True Boolean
IsLocalizable False Boolean
IsReadOnly False Boolean
Name "ContextMenuStrip" String
+ PropertyType {Name = "ContextMenuStrip" FullName =
"System.Windows.Forms.ContextMenuStrip"} System.Type
SerializationVisibility Visible {1}
System.ComponentModel.DesignerSerializationVisibil ity
SupportsChangeEvents True Boolean
Jun 25 '07 #1
1 1387
Actually, for a converter you should really ask the property itself
(since it can be set against a property using the
TypeConverterAttribute); as such, you should be using (if I can
remember VB syntax):

Dim converter As TypeConverter = Prop.Converter;

If no TypeConverterAttribute is set (for Prop), then this will
automatically use Prop.PropertyType to get a converter for the type
(rather than the instance). In short: it should work, even for null
values.

Marc
Jun 25 '07 #2

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

Similar topics

8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
8
by: deko | last post by:
I'm hoping someone can sanity check my understanding of the Object Model for Forms/Controls. I'm having trouble drilling down into Control properties. First, I have a record set with the...
10
by: Sunny | last post by:
Hi, I have an old problem which I couldn't solve so far. Now I have found a post in that group that gave me an idea, but I can not fully understand it. The problem is: I'm trying to use a...
3
by: Sam Sungshik Kong | last post by:
Hello! While using panel control, I wondered a thing. Panel class is subclass of Control class. Control class has KeyPress event and Focus() method, etc... Then Panel class must have them. I...
3
by: countd4 | last post by:
I have built a working user control. However, to make it work, I always have to set certian properties using the properties sheet for the control when using it on other forms. I want to be able to...
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...
4
by: TS | last post by:
When i try to access the page class or parent properties inside a server control that is nested in another server control, they are null. I don't even call CreateChildControls for the parent...
1
by: Christophe Peillet | last post by:
I have a CompositeControl with two types of properties: 1.) Mapped Properties that map directly to a child control's properties (ex.: this.TextboxText = m_txt.Text). These properties are handled...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
10
by: Derek Hart | last post by:
I am going in circles trying to loop through properties on 3rd party controls. For example, I have a textbox that has its maximum length located at MyTextBox.Properties.MaxLength - instead of the...
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
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...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.