473,386 Members | 1,997 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,386 software developers and data experts.

Reflection API

Hello All:

I'm stuck with this. I'm trying to obtain the SelectedValue property
for a combobox control on UserControl using reflection.

So I write:
PropertyInfo pi =
objControl.GetType().GetMember("cmbComplex").GetTy pe().GetProperty("SelectedValue");

This always returns a value null, and throws an exception hence.

When I debug through this using QuickWatch, I get to see that
objControl.GetType().GetMember("cmbComplex") evaluates to a ComboBox
indeed.

But why is that I'm unable to see the SelectedValue Property through
this?

Am I missing something obvious?

TIA.

Sk&y;

Apr 9 '06 #1
5 2817
On 9 Apr 2006 15:27:44 -0700, "Skandy" <sk****************@gmail.com>
wrote:
Hello All:

I'm stuck with this. I'm trying to obtain the SelectedValue property
for a combobox control on UserControl using reflection.

So I write:
PropertyInfo pi =
objControl.GetType().GetMember("cmbComplex").GetT ype().GetProperty("SelectedValue");

This always returns a value null, and throws an exception hence.

When I debug through this using QuickWatch, I get to see that
objControl.GetType().GetMember("cmbComplex") evaluates to a ComboBox
indeed.

But why is that I'm unable to see the SelectedValue Property through
this?

Am I missing something obvious?

TIA.

Sk&y;


First off all try to break up the statement. Is the returned combobox
really the required instance or not. Even though the QuickWatch
returns the type correct; you should (in sake of save coding)
determine if the getmember("cmb...") is not null. And you'll need that
object (combo) in the GetValue statement as well.

Further more is the selectedvalue property (you could see that in the
QuickWatch) public available?

The PropertyInfo (for the value that is) should be queried for the
value:

Expand|Select|Wrap|Line Numbers
  1. PropertyInfo oInfo = oTestObj.GetType().GetProperty("SelectedValue");
  2. int iValue = (int)oInfo.GetValue(oTestObj, null);
  3.  
in the code above the oTestObj is your combobox.

greetings
Leon
Apr 9 '06 #2
Hi leon:

Thanks for the reply.

I just verified that I dont have an object of type
System.Windows.Forms.ComboBox returned by the call:

objControl.GetType().GetMember("cmbComplex").

The above call returns an object of type MemberInfo.
Now given this fact, is there anyway that I can get a handle of the
ComboBox, something like:

ComboBox cmb = (ComboBox)mi.......

where mi is the member variable.

I dont seem to get this.

Thanks again.
Sk&y;

Apr 9 '06 #3
Hello:

Got that one working.

Split it as:

FieldInfo objFieldInfo =
(FieldInfo)objControl.GetType().GetMember("cmbComp lex")[0];
ComboBox objCombo =
(ComboBox)objFieldInfo.GetValue(objControl);
objCombo.SelectedValue = objReader.GetValue(0);
and its all working now!

Thanks again for looking into my problem!

regards,
Sk&y;

Apr 9 '06 #4
On 9 Apr 2006 16:07:59 -0700, "Skandy" <sk****************@gmail.com>
wrote:
Hi leon:

Thanks for the reply.

I just verified that I dont have an object of type
System.Windows.Forms.ComboBox returned by the call:

objControl.GetType().GetMember("cmbComplex").

The above call returns an object of type MemberInfo.
Now given this fact, is there anyway that I can get a handle of the
ComboBox, something like:

ComboBox cmb = (ComboBox)mi.......

where mi is the member variable.

I dont seem to get this.

Thanks again.
Sk&y;


The easy way around this: create a property which returns your
combobox (public) and get that value using
"GetProperty(...)...GetValue(...)"

Otherwise I assume, never got into this that deep, you need to fetch
your combobox from the (nested)controls collection from the
usercontrol/form (in your case usercontrol).

Leon
Apr 9 '06 #5
Hi Leon:

I agree that the way to obtain Property values is through the
PropertyInfo class.

But what I was trying to achieve here is to obtain the combobox's
reference from my user control. The following code got me just that.

FieldInfo objFieldInfo =
(FieldInfo)objControl.GetType().GetMember("cmbComp lex")[0];
ComboBox objCombo =
(ComboBox)objFieldInfo.GetValue(objControl);

The trouble that I was facing was that the objControl's reference is
not known in the class that I'm coding in and I was wondering how to
obtain the combo's reference.

Thanks again!

Apr 9 '06 #6

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

Similar topics

0
by: A. Wiebenga | last post by:
Hi all! I am a student at the Hogeschool van Arnhem en Nijmegen in Holland. I am currently involved in a research project regarding Reflection. Purpose of the research project is to document...
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...
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...
2
by: Mark | last post by:
Am I out of my mind if I use Reflection everytime someone logs into our site to get and track the current Major/Minor/Build/Revision version that the person is viewing our site through? This...
0
by: Shawn Hogan | last post by:
Hi everyone, I've been trying to execute a control's private event code via reflection from another class with the goal of potentially doing some unit testing. The examples below are trying to...
3
by: HL | last post by:
The requirement is to send some information to other objects. The objects to whom the information has to be sent is not available at compile time. The names of the types (objects) will be provided...
9
by: Kuberan Naganathan | last post by:
Hello all Does anyone know of a good way to use reflection in c++? I don't mean simply using rtti or dynamic casting. I'm talking about java/c# style reflection where an actual instance of...
17
by: raylopez99 | last post by:
What good is C# Reflection, other than to find out what types are in an assembly? And to dynamically invoke methods in an assembly (.dll or .exe)? Also, bonus question, can you use Reflection...
0
by: Gustavo Arriola | last post by:
Hola a todos! Estoy intentando ejecutar un método usando Reflection. El código es el siguiente: public static void SoapHandler(Exception Error) { try { Type assemblyType;
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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,...

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.