views:

27

answers:

1

I am having difficulty binding to a property on my object.

This is my property:

    private int? Tid;
    private int? innerTenantID { 
        get { return Tid; } 
        set { 
            Tid = value; 
            innerTenant = (value.HasValue)? Tenant.GetTenantByID(value.Value) : null;
        } 
    }

And this is my attempt to bind:

        this.DataBindings.Add(new Binding("innerTenantID", tblCashReceiptsBindingSource, "TenantID"));

I get, ArguementException, "Cannot bind to the Property 'innerTenantID' on the target control. Prameter name: PropertyName;

The TenantID value is a nullable integer.

+3  A: 

The first thing I see, is that the getter and setter is not public. Probably this is the problem.

    private int? Tid; 
    public int? innerTenantID {  
        get { return Tid; }  
        set {  
            Tid = value;  
            innerTenant = (value.HasValue)? Tenant.GetTenantByID(value.Value) : null; 
        }  
    } 
HCL
Yes, private properties are rarely useful. And don't bind well.
Henk Holterman