473,587 Members | 2,229 Online
Bytes | Software Development & Data Engineering Community
+ 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 1735
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******@discu ssions.microsof t.com> wrote in message
news:C3******** *************** ***********@mic rosoft.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
7350
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...
7
371
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 user input (file values when file is opened). I was hoping to put the name of the property in the tag of each control and fire an event if the a file...
8
1579
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 reproducing the scenario in a simpler way, but it's slow going, and maybe there is something very basic I don't know yet.... Given the following lines of...
5
2190
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 achieved as Form.Controls.Add(objUserControl); Now in my code I have the following:
0
1172
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 class in my program. Each of these classes is a descendant of a 'DataType' class. After reading about reflection, I though I could use this naming in my...
1
1464
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 tags to a higher level. (https://bugzilla.mozilla.org/show_bug.cgi?id=353575) i.e. ....
1
2615
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 control to create the XmlAttributes for the Control's XAML node. The problem is, regardless of how I set the 'Visible' property for a control in the...
5
4283
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 delegate: public class DelegateEx {
6
1960
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 quiet and smiled. What is reflection!? I have been reading it up, and all I can work out is that it has something to do with Late Binding, and...
0
8205
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. ...
0
8339
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...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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...
0
6619
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...
1
5712
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...
0
5392
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...
0
3840
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...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.