Link to home
Start Free TrialLog in
Avatar of tiwengr
tiwengr

asked on

GetControlPropertyValue code won't compile

I am struggling through a BackgroundWorker problem which is new to me and have been seeking help to get it working properly.  I have received some expert comments but one of the methods suggested will not compile.  Since that question is not getting any replies now, I am trying to break the problem into smaller pieces so that someone will help with the smaller part of the problem.

Here's the code:

delegate object GetControlValueCallback(Control ctrl, string propertyName);
 
private object GetControlPropertyValue(Control ctrl, string propertyName)
{
    if (ctrl.InvokeRequired)
    {
        GetControlValueCallback d = new GetControlValueCallback(GetControlPropertyValue);
        return ctrl.Invoke(d, new object[] { ctrl, propertyName});
    }
    else
    {
        Type t = ctrl.GetType();
        PropertyInfo[] props = t.GetProperties();
        foreach (PropertyInfo p in props)
        {
            if (p.Name.ToUpper() == propertyName.ToUpper())
            {
                return p.GetValue(ctrl, propertyValue);
            }
        }
    }
}

Unfortunately I get the following error when trying to compile:

Error      3      The name 'propertyValue' does not exist in the current context

Any suggestions would be greatly appreciated!
ASKER CERTIFIED SOLUTION
Avatar of sumix
sumix

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tiwengr
tiwengr

ASKER