473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 xyzBindingSource - Column1
To become: xyzBindingSource - 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.normalColTextBox.DataBindings.Add(
new System.Windows.Forms.Binding(
"Enabled", this.dataTable1BindingSource, "ColumnX", true,
OnPropertyChanged, "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 3238
cjard,

When binding to a data set, it uses the implementation of
ICustomTypeDescriptor 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.com

"cjard" <mc**@aber.ac.ukwrote in message
news:11**********************@m36g2000hse.googlegr oups.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 xyzBindingSource - Column1
To become: xyzBindingSource - 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.normalColTextBox.DataBindings.Add(
new System.Windows.Forms.Binding(
"Enabled", this.dataTable1BindingSource, "ColumnX", true,
OnPropertyChanged, "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.guard.caspershouse.comwrote:
cjard,

When binding to a data set, it uses the implementation of
ICustomTypeDescriptor 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.Diagnostics.DebuggerNonUserCodeAttribute()]
public string PKCol {
get {
return ((string)
(this[this.tableDataTable1.PKColColumn]));
}
set {
this[this.tableDataTable1.PKColColumn] = 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<RowState, 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 myControlCollection)
c.Enabled = c.Tag[currentRow.RowState];
}

//currentRow is a property that deduces the current row from
BindSource.Current
//myControlCOllection 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
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...
2
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...
0
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...
3
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...
2
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...
14
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...
0
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....
7
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....
6
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='<%#...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.