473,779 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How does .NET property databinding work?

I ask, because I have a textbox bound to a bindingsource, which is
bound to a datatable(row)

The datatable is typed, and hence exports a Property called Column1
I added another property to the datatable by editing the partial
class, and Called it ColumnX - it simply returns "Hello World" all the
time

Then I tried to bind my textbox to it, editing the binding for .Text
from xyzBindingSourc e - Column1
To become: xyzBindingSourc e - ColumnX

Upon starting the app, I receive the error that "Cannot bind to the
property or column ColumnX on the DataSource."

The autogenerated code to do the binding looks like:
this.normalColT extBox.DataBind ings.Add(
new System.Windows. Forms.Binding(
"Enabled", this.dataTable1 BindingSource, "ColumnX", true,
OnPropertyChang ed, "False"
)
);

What voodoo is going on here, whereby my datatablerow does indeed have
2 properties, Column1 and ColumnX, but only one of them is available
for binding?

Jun 8 '07 #1
2 3266
cjard,

When binding to a data set, it uses the implementation of
ICustomTypeDesc riptor on the row to determine what properties to bind to,
not reflection on the properties. The reason your property doesn't show up
is that the data row takes its type description from the columns on the
underlying table. So if you want your row to expose that property through
databinding, you have to add the column to the underlying table, and then
expose the value of the property by getting the value from the underlying
row.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"cjard" <mc**@aber.ac.u kwrote in message
news:11******** **************@ m36g2000hse.goo glegroups.com.. .
>I ask, because I have a textbox bound to a bindingsource, which is
bound to a datatable(row)

The datatable is typed, and hence exports a Property called Column1
I added another property to the datatable by editing the partial
class, and Called it ColumnX - it simply returns "Hello World" all the
time

Then I tried to bind my textbox to it, editing the binding for .Text
from xyzBindingSourc e - Column1
To become: xyzBindingSourc e - ColumnX

Upon starting the app, I receive the error that "Cannot bind to the
property or column ColumnX on the DataSource."

The autogenerated code to do the binding looks like:
this.normalColT extBox.DataBind ings.Add(
new System.Windows. Forms.Binding(
"Enabled", this.dataTable1 BindingSource, "ColumnX", true,
OnPropertyChang ed, "False"
)
);

What voodoo is going on here, whereby my datatablerow does indeed have
2 properties, Column1 and ColumnX, but only one of them is available
for binding?
Jun 9 '07 #2
On Jun 9, 9:51 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guar d.caspershouse. comwrote:
cjard,

When binding to a data set, it uses the implementation of
ICustomTypeDesc riptor on the row to determine what properties to bind to,
not reflection on the properties.
Oh, what a nuisance. Is there any way to access the code that is doing
the examination of the row?
The reason your property doesn't show up
is that the data row takes its type description from the columns on the
underlying table. So if you want your row to expose that property through
databinding, you have to add the column to the underlying table, and then
expose the value of the property by getting the value from the underlying
row.
This creates significant drag for me.. I was hoping to avoid such a
nuisance. Can you think of a better way to do it, rather than adding
dummy columns, that I will never use, just so I can bind some boolean
properties to values that can be easily calculated from the state of
the row? The annoying thing is, that if I have to add dummy columns,
the number of columns present in the dataset will triple.

Alternately, can some more intelligent code be used to form a row's
value? For example, the Expression property can add two columns
together, but I want a more intelligent coding hook.. If there were
some way to make a column call to a property for its value in a way
that wont be destroyed by the design autogenerator, I'd like to hear
it :)
e.g. the designer generates this:

[System.Diagnost ics.DebuggerNon UserCodeAttribu te()]
public string PKCol {
get {
return ((string)
(this[this.tableDataT able1.PKColColu mn]));
}
set {
this[this.tableDataT able1.PKColColu mn] = value;
}
}
I'd like to generate the equivalent (indeed I have already done so but
it is not enumerated as per your explanation) by hand and not have the
designer destroy it when it is run.

Could I, for example, create a custom class and set my column to be of
that type.. When called upon for its value, can that class determine
the row it is on, and hence deduce the boolean necessary for binding?
Is this a hugely memory intensive solution to the relatively trivial
problem?
Another, less sophisticated approach I considered was simply of having
a custom class that is essentially a Dictionary<RowS tate, boolean>
stored in the .Tag of each control on the form and upon the
bindingsource positionchanged event, just enumerating all the cotnrols
on the form and setting their enabled-ness relative to what is gotten
out of the Tag dictionary:

PositionChanged (object sender, EventArgs e){
foreach(Control c in myControlCollec tion)
c.Enabled = c.Tag[currentRow.RowS tate];
}

//currentRow is a property that deduces the current row from
BindSource.Curr ent
//myControlCOllec tion is a manually built collection of controls that
must be changed enabled-ness

Jun 11 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
5430
by: Patrick B | last post by:
I'm wondering about the mechanics of databinding. Say that a textbox is bound to a property of a business object. The business object is a "Person". The control is a textbox called "ctlFirstName", and it's bound to the "FirstName" property of "Person". Why doesn't the following work? myForm.Show(); Person p = new Person();
2
1720
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can anyone help with the required syntax? if i do TExtbox1.text = x.firstname it works ok, but I want to edit the textbox setting the value of x.firstname.
0
1144
by: Ahmet GUNES | last post by:
Hi all, Although I tried several different ways, I wasn't able to succeed databinding a parameterized property. Can anyone help? Thanks in advance, AG In a form with two text boxes on it, say in Load event, I write the following code:
3
1862
by: John Bailey | last post by:
When I first built a few web pages in ASP .Net 2.0, I thought it was great. The formview and detailview contorls would automatically layout the controls for you, the update methods were automatically generated, and the objectdatasource let you design against a business object through the gui. Now I am working on my first real web application on 2.0, and I find this automatic functionality doesn't do much beyond allowing me to generate...
2
1763
by: Shane | last post by:
When I click on the DataBinding in the properties window a list of options open up called Advanced,Tag and Text. I would like to know what Tag and Text are set to? I hope to Bind a text box to a Access database in my program. -- I am a Noob! Thanks for the Help :)
14
4863
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
0
2155
by: Amit Tyagi | last post by:
Hi Any body can help me i have one problem I have developed one web based application using asp.net 2.0 and vb.net with sql server 2000(I am suing stored procedure) i am also using ajax in this. Its working fine but some times error comes "DataBinding: 'System.Data.Common.DbDataRecord' does not contain a property with the name " and "Overload resolution failed because no Public '=' can be called with these arguments: 'Public Shared Operator...
7
1890
by: Computer Guru | last post by:
Hi, Pardon the unclear/verbose subject, I just can't think of another way of phrasing it. Basically, I can assign the (for instance) "Location" property of a picture box to a data-bound item. Like, I can get the absoloute location from an ADO.NET database, and assign it to the PictureBox.Location property.
6
2904
by: Dmitry Duginov | last post by:
Hi, I have the following label markup (label is inside FormView): <asp:Label ID="lblIndicatorReady" runat="server" Text="RE" ToolTip="Ready" BackColor='<%# Eval("Ready").ToString()=="True"?System.Drawing.Color.FromName("#FFFF80"):System.Drawing.Color.White %>' Enabled='<%# Eval("Ready") %>'
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10306
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.