View previous topic :: View next topic |
Author |
Message |
jimcegelski
Joined: 06 Jul 2009 Posts: 2
|
Posted: Mon Jul 06, 2009 2:34 pm Post subject: Binding a column to an object property that requires a param |
|
|
Hi...I have a need to add columns on the fly, which was easy enough, but I'm having troubles binding the new columns to my object. I typically bind each column to a property on my object but in this case, the property requires a passed parameter. Is there any way to bind a column to a property that requires a parameter? I don't get any error messages but the get method for that property is never called.
Thanks in advance for your response. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jul 06, 2009 10:48 pm Post subject: |
|
|
You will need use programmatic binding (rather than object binding) for this property. To do this you handle the GetCellData event. You can still use the object bindings to handle other properties.
The code below shows an example, assuming your object type is MyItem and the column you are binding to is called "colProblemMethod":
Code: | private void _virtualTree_GetCellData(object sender, GetCellDataEventArgs e)
{
// get the default binding for the given row and use it to populate the cell data
//
RowBinding binding = _virtualTree.GetRowBinding(e.Row);
binding.GetCellData(e.Row, e.Column, e.CellData);
if (e.Row.Item is MyItem && e.Column == this.colProblemMethod)
{
MyItem myItem = e.Row.Item as MyItem;
e.CellData.Value = myItem.ProblemMethod("foo");
}
} |
Another alternative, since you are doing things on the fly, may be to create your own RowBinding class (probably derived from ObjectRowBinding) _________________ Infralution Support |
|
Back to top |
|
|
jimcegelski
Joined: 06 Jul 2009 Posts: 2
|
Posted: Tue Jul 07, 2009 7:46 pm Post subject: |
|
|
Thanks very much...the code you provided worked perfectly. |
|
Back to top |
|
|
|