473,614 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ 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 PropertyDescrip tor
Dim Props As PropertyDescrip torCollection

Props = TypeDescriptor. GetProperties(C trl)

For Each Prop In Props
Dim PropObject As Object = Prop.GetValue(C trl)
Dim converter As TypeConverter = TypeDescriptor. GetConverter(Pr opObject)
...
Next

Unfortunately the PropObject comes out as nothing for Ctrl =
{System.Windows .Forms.BindingN avigator}on line Dim PropObject As Object =
Prop.GetValue(C trl) and this gives 'System.Argumen tException was unhandled'
error on the line Dim converter As TypeConverter =
TypeDescriptor. GetConverter(Pr opObject). 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.Compone ntModel.Reflect PropertyDescrip tor}
System.Componen tModel.Property Descriptor
+ System.Componen tModel.ReflectP ropertyDescript or
{System.Compone ntModel.Reflect PropertyDescrip tor}
System.Componen tModel.ReflectP ropertyDescript or
+ Attributes {System.Compone ntModel.Attribu teCollection}
System.Componen tModel.Attribut eCollection
Category "Behavior" String
+ ComponentType {Name = "Control" FullName =
"System.Windows .Forms.Control" } System.Type
+ Converter {System.Compone ntModel.Compone ntConverter}
System.Componen tModel.TypeConv erter
Description "The shortcut menu to display when the user right-clicks the
control." String
DesignTimeOnly False Boolean
DisplayName "ContextMenuStr ip" String
IsBrowsable True Boolean
IsLocalizable False Boolean
IsReadOnly False Boolean
Name "ContextMenuStr ip" String
+ PropertyType {Name = "ContextMenuStr ip" FullName =
"System.Windows .Forms.ContextM enuStrip"} System.Type
SerializationVi sibility Visible {1}
System.Componen tModel.Designer SerializationVi sibility
SupportsChangeE vents True Boolean
Jun 25 '07 #1
1 1552
Actually, for a converter you should really ask the property itself
(since it can be set against a property using the
TypeConverterAt tribute); as such, you should be using (if I can
remember VB syntax):

Dim converter As TypeConverter = Prop.Converter;

If no TypeConverterAt tribute is set (for Prop), then this will
automatically use Prop.PropertyTy pe 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
16654
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 frm.Properties If prp.Name = rst!PropName Then prp = rst!ChangeTo
8
3352
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 following for a given Form: 1)Container
10
7360
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 Windows.Forms.UserControl in a COM environment, i.e. I want to host that control in a COM host. So far, so good, I can host it, but I can not reach the parent COM object from the control (Parent property is null :( ). I have stopped the control in the...
3
1604
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 guess it *has* then behind even if they are not meaningful. However, the code complete tool doesn't show them when I type panel1.(code complete list). Actually I can type panel1.Focus() without any compilation error.
3
6629
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 set default values for most properties so the control will work as-is without requiring the developer to set them. I notice in the compment initialization code create when I drop the control on a form that all the properties are set to null or...
2
3169
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 problems that I have encountered to date and the solutions (if any) that I found. http://users.adelphia.net/~brianpclab/ServerControlCollectionIssues.htm This page also has all of the source code in a compressed file that you are free to download...
4
2432
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 control until its pre-render event, so i know the parent control is on the page. Any ideas? thanks
1
1659
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 by their underlying classes (such as the TextBox control), and are not persisted by me. 2.) Unique Properties that don't map directly and are persisted in ViewState (ex.: this.LabelPosition, which specifies where on the form the label should be...
6
11067
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
10
1853
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 dotnet textbox which is MyTextBox.MaxLength. If I loop a built in dotnet control, it finds the property no problem. But looping through the 3rd party control, Properties.MaxLength does not get listed. I was hoping to find how it names it using...
0
8627
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8579
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8433
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7093
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5540
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4127
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1425
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.