Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I understand the databinding concepts, however I have an issue.

 

When binding controls on a usercontrol to a custom object I am left to use late binding.

[csharp]

txtAccount.DataBindings.Add(new Binding("Text", _customer, "Account"));

[/csharp]

 

This completely defeats the purpose of design-time validation of properties which would occure if I do this

[csharp]

txtAccount.Text = _customer.Account;

[/csharp]

 

I could of course use reflection to get a list of properties from the object and a list of textbox/property-name pairs, iterate through it and bind them all dynamically. However this approach seems to be utilizing more resources than needed (by going through reflection object model) and does not fit into the application architecture well.

 

Wouldn't it be nice to be able write a simple line like so

[csharp]

txtAccount.DataBindings.Add(new Binding("Text", _customer, _customer.Account.PropertyName));

[/csharp]

or even

[csharp]

txtAccount.DataBindings.Add(new Binding("Text", _customer, nameof(_customer.Account)));

[/csharp]

 

Anyone?

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...