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:
-
PropertyInfo oInfo = oTestObj.GetType().GetProperty("SelectedValue");
-
int iValue = (int)oInfo.GetValue(oTestObj, null);
-
in the code above the oTestObj is your combobox.
greetings
Leon