Databinding custom properties of subclasses.

Posts   
 
    
BlueCell avatar
BlueCell
User
Posts: 83
Joined: 12-Jul-2004
# Posted on: 13-Feb-2005 19:02:21   

Hi,

I have two subclasses (lets call them A and B), which both inherit from the same baseclass, which has a property named "State" (defined as a State enum). A has B (as in private member variable). Now I would like to databind in some function, for example in the ctor, the "State" property of A to the "State" property of B. Currently I have:


Me.B.DataBindings.Add("State", Me, "State")

Unfortunatly, this throws the error: Object type cannot be converted to target type. Anyone had any luck where you have managed to get this working? If so, could you pls help me out here...

TIA,

Michel van den Berg

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Feb-2005 10:33:43   

B is a derived class of Control?

Frans Bouma | Lead developer LLBLGen Pro
BlueCell avatar
BlueCell
User
Posts: 83
Joined: 12-Jul-2004
# Posted on: 14-Feb-2005 11:37:01   

Indirectly, yes. The baseclass where both classes inherit from, inherits control.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 14-Feb-2005 12:41:42   

BlueCell wrote:

Indirectly, yes. The baseclass where both classes inherit from, inherits control.

Hmm, sounds odd. It looks the same as if you're binding one textbox' text property to another textbox' text property. I'm not sure if that works (databinding is strange stuff. what looks logical isn't always logical in the databinding universe)

Frans Bouma | Lead developer LLBLGen Pro
BlueCell avatar
BlueCell
User
Posts: 83
Joined: 12-Jul-2004
# Posted on: 15-Feb-2005 16:45:37   

Got it! I had to implement a Public Event [propertyname]Changed As EventHandler

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 15-Feb-2005 17:51:13   

BlueCell wrote:

Got it! I had to implement a Public Event [propertyname]Changed As EventHandler

Oh indeed!... the most silly requirement ever but if you forget these databinding falls apart pretty quickly... disappointed Ok, I'll stop now before I start a rant.. wink

Frans Bouma | Lead developer LLBLGen Pro