473,421 Members | 1,751 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,421 software developers and data experts.

Using Reflection to get a Field Value from Control

I am writing a simulation program, the main classes inherit from a base class
which itself inherits from Control. I am using reflection to serialize these
objects including the fields from control. This works perfectly apart from
the field text in Control which always comes back null. Although the IDE
always shows it having the correct value. Since the IDE presumably uses
reflection to show the value, I am at a loss to know why this one field is a
problem. Interestingly, the command window also comes back with a null, when
doing the same operation, but if you do the operation on the original object
just after creation it is correct. It is worth noting the objects are placed
in a Collection before serialization. So it is using FieldInfo.GetValue on
the items in the Collection which is failing on the string field.
Nov 17 '05 #1
3 2517
Tony,

Are you reflecting on the field, or on the property? I don't think that
most controls store the text themselves. Rather, when you call the Text
property, it calls SendMessage with a WM_GETTEXT message to get the text
contents of the control, which is why the text field would be blank.

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

"tony lock" <to******@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
I am writing a simulation program, the main classes inherit from a base
class
which itself inherits from Control. I am using reflection to serialize
these
objects including the fields from control. This works perfectly apart from
the field text in Control which always comes back null. Although the IDE
always shows it having the correct value. Since the IDE presumably uses
reflection to show the value, I am at a loss to know why this one field is
a
problem. Interestingly, the command window also comes back with a null,
when
doing the same operation, but if you do the operation on the original
object
just after creation it is correct. It is worth noting the objects are
placed
in a Collection before serialization. So it is using FieldInfo.GetValue on
the items in the Collection which is failing on the string field.

Nov 17 '05 #2
I am reflecting on the field text which provides the property Text, this
works when done at the form level but not during serialization. In fact it is
more complicated than that. I set up a test program, that inherited a very
simple class from control and found that it picked up the field properly,
using exactly the same class for serialization as I am using in the main
program. The field is certainly there in the main program but comes up as
null, in the test program it comes up properly. All of which leaves me at a
loss as to what is going on.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tony,

Are you reflecting on the field, or on the property? I don't think that
most controls store the text themselves. Rather, when you call the Text
property, it calls SendMessage with a WM_GETTEXT message to get the text
contents of the control, which is why the text field would be blank.

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

"tony lock" <to******@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
I am writing a simulation program, the main classes inherit from a base
class
which itself inherits from Control. I am using reflection to serialize
these
objects including the fields from control. This works perfectly apart from
the field text in Control which always comes back null. Although the IDE
always shows it having the correct value. Since the IDE presumably uses
reflection to show the value, I am at a loss to know why this one field is
a
problem. Interestingly, the command window also comes back with a null,
when
doing the same operation, but if you do the operation on the original
object
just after creation it is correct. It is worth noting the objects are
placed
in a Collection before serialization. So it is using FieldInfo.GetValue on
the items in the Collection which is failing on the string field.


Nov 17 '05 #3
You can never assume that the field text is properly set. Therefore you
should use the property Text which should always be set correctly.
"tony lock" <to******@discussions.microsoft.com> schrieb im Newsbeitrag
news:18**********************************@microsof t.com...
I am reflecting on the field text which provides the property Text, this
works when done at the form level but not during serialization. In fact it is more complicated than that. I set up a test program, that inherited a very
simple class from control and found that it picked up the field properly,
using exactly the same class for serialization as I am using in the main
program. The field is certainly there in the main program but comes up as
null, in the test program it comes up properly. All of which leaves me at a loss as to what is going on.

"Nicholas Paldino [.NET/C# MVP]" wrote:
Tony,

Are you reflecting on the field, or on the property? I don't think that most controls store the text themselves. Rather, when you call the Text
property, it calls SendMessage with a WM_GETTEXT message to get the text
contents of the control, which is why the text field would be blank.

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

"tony lock" <to******@discussions.microsoft.com> wrote in message
news:E0**********************************@microsof t.com...
I am writing a simulation program, the main classes inherit from a base
class
which itself inherits from Control. I am using reflection to serialize
these
objects including the fields from control. This works perfectly apart from the field text in Control which always comes back null. Although the IDE always shows it having the correct value. Since the IDE presumably uses reflection to show the value, I am at a loss to know why this one field is a
problem. Interestingly, the command window also comes back with a null, when
doing the same operation, but if you do the operation on the original
object
just after creation it is correct. It is worth noting the objects are
placed
in a Collection before serialization. So it is using FieldInfo.GetValue on the items in the Collection which is failing on the string field.


Nov 17 '05 #4

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

Similar topics

0
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
2
by: Jason Coyne Gaijin42 | last post by:
I have seen several people looking for a way to access the Columns collection when using the AutoGenerate = true option. Some people have gotten so far as to find the private autoGenColumnsArray...
1
by: Mudassar | last post by:
i want to get the property value using reflection. Scenerio: i have a status bar on MDI form. it has property named "Panels" and i want to get a specific panel from that panels collection using...
5
by: rettigcd | last post by:
I have several classes that all have the same static member: class A{ public static string Table = "TableA"; } class B{ public static string Table = "TableB"; }
2
by: Dan | last post by:
hi newsgroup, i need server side validation of user entries. as i do have many fields, i would like to use reflection for checkinng the IsValid property of all the Validators. here is the...
5
by: Eric Goforth | last post by:
Hello, I have a generic subroutine that I pass an object and fieldname as arguments. The subroutine then uses reflection to search for the value of the fieldname. For example: 'Calling...
9
by: Mario Vázquez | last post by:
Hi, I have a component which exposes an extended property. I want to edit this property using a UITypeEditor. The problem is that when the designer raises my UITypeEditor sends a reference of...
2
by: Luis Arvayo | last post by:
Hi, In c#, I need to dynamically create types at runtime that will consist of the following: - inherits from a given interface - will have a constructor with an int argument
3
by: Steve Amey | last post by:
Hi all I am using reflection to read the values of properties from a class. The class is returned from a Web Service so I have to access the class using FieldInfo (Using VS 2003 which converts...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
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
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...

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.