473,698 Members | 2,594 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

creating a form that will display all the properties of an object

Hello.

I have a project that consists of nine different objects, each serving
their own purpose. In the past I have just created a form for each
one, and then whenever you call, say, object.Display( ), it would call
up the form associated with that object. This form only displays
information, it doesn't allow the user to edit any information. Is it
possible to find the properties of a certain object, and then loop
through creating labels and such for every property? I believe I've
heard the Reflection class mentioned somewhere, but from what I see in
the MSDN library, it may not be exactly what I'm looking for. I also
only want to display the properties I defined.

Thank you,
JJ L.
Nov 16 '05 #1
2 1533
JJ,

In order to do this, you would have to use reflection. You would use
reflection to get the property names, and then create UI elements that are
linked to those properties on the instance of the object you have.

An easier alternative would be to use the PropertyGrid class, which does
all of this for you.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"JJ L." <po******@gmail .com> wrote in message
news:69******** *************** ***@posting.goo gle.com...
Hello.

I have a project that consists of nine different objects, each serving
their own purpose. In the past I have just created a form for each
one, and then whenever you call, say, object.Display( ), it would call
up the form associated with that object. This form only displays
information, it doesn't allow the user to edit any information. Is it
possible to find the properties of a certain object, and then loop
through creating labels and such for every property? I believe I've
heard the Reflection class mentioned somewhere, but from what I see in
the MSDN library, it may not be exactly what I'm looking for. I also
only want to display the properties I defined.

Thank you,
JJ L.

Nov 16 '05 #2
JJ L,

Reflection is exactly what you are after. Reflection is not a class it is
method for discovering inforamtion of objects and classes at run time as
well as dynamically creating objects and executing methods. If you want to
discover all the proerties and get their values of objects you know nothing
about Reflection is exactly what you need.

Look at
Object.GetType method and/or C# typeof operator
Type class
Type.GetPropert ies method
PropertyInfo class

If you need something like VS property browser, you have it out of the box.
Look at PropertyGrid component.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"JJ L." <po******@gmail .com> wrote in message
news:69******** *************** ***@posting.goo gle.com...
Hello.

I have a project that consists of nine different objects, each serving
their own purpose. In the past I have just created a form for each
one, and then whenever you call, say, object.Display( ), it would call
up the form associated with that object. This form only displays
information, it doesn't allow the user to edit any information. Is it
possible to find the properties of a certain object, and then loop
through creating labels and such for every property? I believe I've
heard the Reflection class mentioned somewhere, but from what I see in
the MSDN library, it may not be exactly what I'm looking for. I also
only want to display the properties I defined.

Thank you,
JJ L.

Nov 16 '05 #3

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

Similar topics

4
561
by: Altramagnus | last post by:
I have 30 - 40 type of different window. For each type I need about 20 instances of the window. When I try to create them, I get "Error creating window handle" My guess is there is a maximum number of window handle, because if I reduce to about 2 instances of each window, it can run. But not 20 instances of each window. Does anyone know what the problem is? is it really because it exceeds the maximum number of window handle?
4
8379
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to display the contents of a TIFF image file. According to the very limited documentation that I have been able to locate so far, all I should need to do is to drop the Image Edit Control onto the form in design mode, set the control's Image property to...
1
3404
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set the Required, Allow Zero Length and Indexed attributes. I have tried but keep getting a syntax error. Also, can I set the default value of a field in code? Has anyone some examples of these. TIA
8
3265
by: Oenone | last post by:
Is it possible to create an object which can have methods and properties, but which can also be treated as a string? I'm trying to create a wrapper around the IIS Request.Form object which behaves the same as the classic ASP object behaved. This will allow me to quickly get a large amount of code up and running (I can then tweak it to not require this wrapper at a more leisurely pace). When queried directly, this object returns a...
6
2879
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
4
2752
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
10
2226
by: Jake Forson | last post by:
Hi there, I'd like to re-create a form given only its resource file. I was going to simply read the resource file and re-create the "Form" object and all its controls as found in this file (applying all properties in the file and relying on the default properties for those not found). After looking at "InitializeComponent()" however (which is what I'm really trying to re-produce here), can somone explain why this function does the...
26
5363
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is because I am not always able to control/create all the different constructors the base class has. My problem can be described in code as follows ... /* This is the base class with a whole heap of constructors/functionality*/ public class Animal
9
3625
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have to create the dynamic controls in the OnInit stage of the lifecycle. Since data from static controls is not yet available in the OnInit stage I can't know what dynamic control I have to create.
0
8678
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8609
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9166
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...
1
6525
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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
4371
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4621
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
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
3
2007
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.