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