Jump to content
Xtreme .Net Talk

How to interograte binding properties, when it's different for each control ??


Recommended Posts

Posted

Hi,

 

I'm writing a generic class to support databinding in a form.

 

I have a formfields collection which collects formfield objects which have each fieldname, controlname, mandatory, defaultvalue and originalvalue properties.

 

The problem i have is that when I want to check the value in the control, this could be stored in one of a few different properties (at the moment - text, checked, value, selectedvalue).

 

I would like to have a BindingProperty on the formfield object that states which property is the binding property. This would be a string ("text", "checked", "value", "selectedvalue", this would supply the binding.add method when I loop through and bind the controls).

But how do I get the value of the property when the propertyname is stored as a string??

Can you reference a controls property some other flashier way??

 

Am I barking up the wrong tree, or has someone already does this somewhere ......? (don't care if they have though, this is great learning curve!!!)

 

Cheers

 

Alex Stevens

Gloucester, England

Posted

Solved:

 

Managed to solve this without using relflection, using the callbyname function.

It allows you to get/set a property of an object:

 

CallByName(txtForename, "Text", CallType.Get)

CallByName(txtForename, "Text", CallType.Set, "Alex")

 

Alex

  • *Experts*
Posted

Normally you don't care about the value of the control. The DataSet (or whatever you're binding to) is usually the "master" of the data and is what you care about. Normally you only care about the value in the control if you're doing some kind of pre-validation before moving the data into the datasource. But, you can usually handle that through the Format/Parse events (Parse is the one to get the data from the control and convert it to whatever is needed in the datasource).

 

But, I'm glad you found a solution :)

 

-Nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...