473,490 Members | 2,592 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1547
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
16620
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
3323
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
7337
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
1588
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
6621
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
3154
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
2413
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
1644
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
11055
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
1835
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
7112
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
6974
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
7146
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,...
1
6852
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7356
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4878
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...
0
4573
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
277
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.