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

Home Posts Topics Members FAQ

Reflection and descendants of Control

I asked this question a while ago, but I now have more information on the
problem.

I have a set of Classes inherited from control that make up a simulation
model. The user drops them on a MDI form to create the model.

Because Control is not serializeable, I am using Reflection to pick up the
fields from the base types when the model is saved.

This works well for most of the properties but fails to save the Text
field, if the control has been added to a form.

If you just create the control and serialize it, the process works
perfectly. However as soon as the control has been added to the controls
collection of a form, reflection returns null for the Text field.

Does anybody out there have any ideas (in particular if anybody at Microsoft
has any thoughts) I would be grateful.
Nov 17 '05 #1
1 1729
Hi Tony,

Short answer - try to get the actual type of the control and invoke the Text
property getter on the actual type, not on the base type.

Long answer - you should separate the model data from its view. Design the
model as a set of serializable classes and use the custom controls just to
display the current state of the model. You can search the Web for the
Model-View-Controller design pattern description for more information on how
this should be properly done.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"tony lock" <to******@discussions.microsoft.com> wrote in message
news:C3**********************************@microsof t.com...
I asked this question a while ago, but I now have more information on the
problem.

I have a set of Classes inherited from control that make up a simulation
model. The user drops them on a MDI form to create the model.

Because Control is not serializeable, I am using Reflection to pick up the
fields from the base types when the model is saved.

This works well for most of the properties but fails to save the Text
field, if the control has been added to a form.

If you just create the control and serialize it, the process works
perfectly. However as soon as the control has been added to the controls
collection of a form, reflection returns null for the Text field.

Does anybody out there have any ideas (in particular if anybody at
Microsoft
has any thoughts) I would be grateful.


Nov 17 '05 #2

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

Similar topics

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...
7
by: John | last post by:
I have a class the reads in a file and sets the values of the file into its properties. This class is used to populate the data onto a form. This form has controls created at runtime based on...
8
by: Rachel Suddeth | last post by:
I'm trying to use reflection to create an object at runtime where the type is given by a string. I thought we should be able to do that, but so far it's not working. I'm trying to work on...
5
by: Skandy | last post by:
Hello All: My second post in as many days! I'm trying to get this working. I have a form and a user control and trying to add the user control to this form. Without reflection this would be...
0
by: Rob | last post by:
Hello, I'm new to C# and have a question regarding factoring through reflection. I have a database filled with data represented by name and value pairs. Each name has a identically named...
1
by: rbrunn | last post by:
Hi all, I'm trying to write a XSL-transformation which converts AI-exported SVG-Files to be more compatible with firefox. Namely I want to extract gradients which are declared inside of symbol...
1
by: =?Utf-8?B?VGltIFBhY2w=?= | last post by:
I am new to Reflection. I am building a windows app that navigates the control tree of a Windows form and creates XAML representing the form. I am using reflection to get the properties of each...
5
by: Klaudiusz Bryja | last post by:
Hi, This is for NetCF 2.0. I need to create event handling code which using reflection. I have some parameters in XML which describe how event should be handled. I have code to create...
6
by: Cralis | last post by:
Hi guys, Someone once said, 'You can do that with reflection'. I can't recall what it was I was trying to do at the time, but then he said, 'Any developer knows what reflection is...'. I kept...
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
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...
1
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
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...
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,...
1
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
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
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.