My requirement is that I need a column with all the usual stuff that GridViewDataColumn usually gives you - display, edit, filter, sort, group etc. But I can't work out how to get a DataMemberBinding value that will do what I want.
It probably makes the most sense if I explain the actual problem rather than trying to make one up, as it's fairly easy to understand.
I have 3 'fixed' columns:
Description (text)
Value (decimal)
Adjusted Value (decimal)
I then have 0->n 'Adjustment' (decimal) columns that get dynamically added in between Value and Adjusted Value. So the idea is that the Value + all Adjustment values = Adjusted Value
So, the value I need to bind to is a decimal, but it requires a method to access it (e.g. 'GetValueForAdjustment(Adjustment adjustment)') and a method to set it (e.g. 'SetValueForAdjustment(Adjustment adjustment, decimal value)').
Now I could probably set DataMemberBinding to use a ValueConverter which will get me the value, sorting, grouping etc. But I'm not going to be able to edit it.
MultiBinding is the other option, but DataMemberBinding doesn't support MultiBinding.
Anything glaring that I'm missing?
7 Answers, 1 is accepted
Why not use dynamics to achieve your goal similar to this demo? The same example can be found in your local copy of our WPF examples.
Kind regards,Vlad
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Thanks - this is a possible solution. However, I think I've possibly found a bug. The DataMemberBinding works fine for me, but IsReadOnlyBinding causes a NullRefrenceException to be thrown every time I try to edit.
The binding from the item ViewModel I'm using for the Items is Adjustments.{id}.Value for DataMemberBinding and Adjustments.{id}.IsReadOnly for IsReadOnlyBinding. Adjustments is a DynamicObject that returns another class with Value and IsReadOnly properties.
It appears that it has trouble creating the access func from the binding when it gets to the dynamic property name.
Can you confirm this is an issue? As a temporary workaround, I can use an event handler to cancel the edit if IsReadOnly == true, but the binding would be neater.
Charles
In the way I set out above, I'm getting a first chance ArgumentException in Telerik.Windows.Data in PropertyPathDescriptor.GetPropertyDescriptor(...). And sorting/filtering etc aren't working for that column.
It seems there's a few issues with Dynamics floating about! I may have to revert to the 'Converter' method and fudge the editor somehow. Neither way is ideal.
I've tried to simulate the problem unfortunately to no avail. Maybe I've missed something.
I'm attaching my sample project for a reference. Could you please let me know how to modify it in order to reproduce the error (or send me your project)?
P.S. You'll have to open a separate support ticket if you want to attach any files.
Nedyalko Nikolov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I can demo the first issue I referred to (with a nested DynamicObject causing a NullReferenceException on accessing the IsReadOnlyBinding). I can't reproduce either of the issues I described in the last post with your example, though - I'll have to try harder!
I'll attach the project for the first issue to a new ticket.
Charles
I will also included a second project that shows that NormalProperty.DynamicProperty.PropertyOnReturnedObject works fine... though I'm getting first chance handling of ArgumentExceptions in mine, but not in this sample. I haven't worked that out yet!
I'm pasting my answer to your support ticket in order to be publicly available.
Thank you for the sample project. I've managed to find the root of the problems.
The problem with displaying and editing the content of a nested property of a dynamic object will be fixed with the next internal build. However the problem with "IsReadOnlyBinding" is not so trivial, since this binding is just a common way to create an expression Func<object, bool> where object is the underlying business object (or row's DataContext) and according to the result cell enters into edit mode or not. Unfortunately this approach does not work with dynamic objects, we will do our best in order to support such scenarios but I cannot commit with any specific date or release. For now I would suggest you to use a simple (not nested) property or use a converter similar to the following:
public
class
TestConverter : IValueConverter
{
#region IValueConverter Members
public
object
Convert(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
MyDataRow dataRow = value
as
MyDataRow;
if
(dataRow !=
null
)
{
return
dataRow[
"IsReadOnly"
];
}
return
value;
}
public
object
ConvertBack(
object
value, Type targetType,
object
parameter, System.Globalization.CultureInfo culture)
{
return
value;
}
#endregion
}
<
Grid.Resources
>
<
local:TestConverter
x:Key
=
"testConverter"
/>
</
Grid.Resources
>
<
telerik:RadGridView
x:Name
=
"radGridView"
AutoGenerateColumns
=
"False"
>
<
telerik:RadGridView.Columns
>
<
telerik:GridViewDataColumn
Header
=
"Name"
DataMemberBinding
=
"{Binding DataRow.Name}"
IsReadOnlyBinding
=
"{Binding DataRow, Converter={StaticResource testConverter}}"
/>
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
Nedyalko Nikolov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.