Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / June 2007

Tip: Looking for answers? Try searching our database.

How to get properties of a control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John - 25 Jun 2007 11:46 GMT
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.DesignerSerializationVisibility
 SupportsChangeEvents True Boolean
Marc Gravell - 25 Jun 2007 12:18 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.