I have a class that calculates the performance and changes in a list of
values, a time-series. I calculate things like week's move,
year-to-date, inception-to-date, and then the pattern kicks in. I need
columns signifying performance every 3 Months, 6 Months, 12 Months, 24
Months, 36 Months, etc.
We wish to allow the user to dynamically add the columns as appropriate
(as the series has 36, 48, 60 months worth of data). The classes i've
created calculate these according to the number of weeks, and i can
easily hard code the properties for the next 20 years, but that
wouldn't be very good design.
C# doesn't support properties with parameters (i'm guessing VB.Net2005
still does). One solution (i think) would be to have a property such as
Peformance(numberWeeks), and pass the parameter through with the
DataPropertyName. We're writing in C# which wouldn't allow this, even
if the grid would.
My next solution would be a method with the same signature, which is
already there. It seems the datagridview doesn't bind to this, as the
method is never called.
Another solution i suppose could be within reflection, and adding
properties to the class at runtime. Not sure if this would work, and if
so not sure if it would be a bit of an overkill.
Am i missing something obvious Can anyone help
Thanks,
Ben

Binding a DataGridViewColumn to a method as opposed to a property
Gboyega
Actually databinding to a method isn't possible. You can create your own CustomPropertyDescriptor and override the GetValue method and get the value from your function or you can handle the DataGridView's CellFormatting event and get the value from your function, but the grid only binds to properties.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
thanks!
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Matthew Adams9346
UntimelyWill
While we're here, can you confirm that the grid can bind to parameterised properties (ala VB) How does the binding work "under the hood"
Shyne79
No, the grid doesn't work with parameterized properties. Parameterized properties in vb come across in IL as an named index property since the CLR doesn't actually support properties that have parameters.< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
this.props = this.currencyManager.GetItemProperties();
this.props[boundColumnIndex].SetValue(this.currencyManager[rowIndex], value);
value = this.props[boundColumnIndex].GetValue(this.currencyManager[rowIndex]);
-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"