This is a migrated thread and some comments may be shown as answers.

Columns bound to enum values produce occasional binding errors

5 Answers 274 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcus
Top achievements
Rank 1
Marcus asked on 05 Jun 2013, 10:31 AM
I have a RadGridView containing 20+ columns, a couple of which are bound to Enum properties.  Both row and column virtualization is turned on.  When I scroll horizontally to bring the enum columns into view, I often get binding errors on the enum columns such as:

System.Windows.Data Error: 6 : 'StringFormat' converter failed to convert value 'Cleared' (type 'BookingStatus'); fallback value will be used, if available. BindingExpression:Path=Value; DataItem='GridViewCell' (Name=''); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String') FormatException:'System.FormatException: Format String can be only "G", "g", "X", "x", "F", "f", "D" or "d".
   at System.Enum.ToString(String format)
   at System.Enum.ToString(String format, IFormatProvider provider)
   at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at System.Windows.Data.BindingExpression.ConvertHelper(IValueConverter converter, Object value, Type targetType, Object parameter, CultureInfo culture)'

My cell template for the Enum columns is very simple, with no explicit StringFormat:

<DataTemplate x:Key="Cell.Enum" DataType="telerik:GridViewCell">
        <TextBlock Text="{Binding Value, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewCell}}}" />
</DataTemplate>

The values for the columns actually do end up displaying correctly, with the enum values such as 'Cleared' all ok.  

I suspect something is wrong with the virtualization - perhaps a column for another type is being reused for my Enum column as I scroll across, and that column's template is being applied to my enum column before all the column's settings are updated to the new column type?

Thanks in advance for your help, this is a fairly big issue for us as it's affecting scroll performance considerably.

I'm using version 2012.3.1017.40.

5 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 05 Jun 2013, 10:50 AM
Hi,

What is the purpose of the custom CellTemplate? Why do you need it? If you leave the column as it is -- do the enum value not show? This FindAncestor binding to the cell itself is really weird. Can you please explain what you are trying to achieve with this strange binding?

If you think that this is a bug in RadGridView, can you please send us a runnable dummy project which we can debug locally?

Thanks in advance.

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcus
Top achievements
Rank 1
answered on 05 Jun 2013, 12:49 PM
I need to CellTemplate because there are other attributes I need to add on the TextBlock such as TextTrimming and TextDecorations.  If I don't apply a custom template nothing changes - I still get the binding errors, but the value displays the same.

How would you suggest I bind to the cell value in a cell template, if not the way I have done?

I'll see if I can get time to put together a sample project, but would appreciate you looking into this in the meantime.

thanks.
0
Rossen Hristov
Telerik team
answered on 05 Jun 2013, 12:53 PM
Hi,

We have already tried to reproduce this, but for some reason we can't see those errors. The fastest way to resolve this issue would be to run and debug a sample project in order to see what is going on. You can open a new support ticket and attach it there. The project can be with dummy data, i.e. dummy everything. You already have the code, so I am sure that it will not take a lot of effort to prepare the sample project.

We are looking forward to hearing from you.

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcus
Top achievements
Rank 1
answered on 05 Jun 2013, 01:59 PM
Support ticket submitted (701195) with working project reproducing the issue.
0
Accepted
Rossen Hristov
Telerik team
answered on 07 Jun 2013, 08:45 AM
Hi,

I have updated the support ticket.

Please, use the built-in properties that our column provides:

col.DataFormatString = "N6";
col.TextAlignment=TextAlignment.Right;
col.TextTrimming=TextTrimming.CharacterEllipsis;
col.TextWrapping = TextWrapping.NoWrap;

You can't do RelativeSource FindAncestor GridViewCell with horizontal virtualization turned on because one and the same cell will be used to show many different columns -- but your TextBlock will remain bound to the first parent it found in the beginning and enter an inconsistent state when horizontal virtualization kicks in.

Alternatively, you can always have a XAML-string with your cell template in code-behind and for each column that you generate modify this string to have a Binding to this column's property and then dynamically load the xaml with 
XamlHelper.LoadXaml. Something like this:

<TextBlock Text="{Binding xxx}"
           TextAlignment="Right"
           TextTrimming="CharacterEllipsis"
           TextWrapping="NoWrap" />

And you replace xxx with the name of the property, load the xaml, cast it to DataTemplate and assign it.

But again, if you did all this simply to set the DataStringFormat  and the three Text* properties, then you should directly set them on the columns and we will set them on our TextBlock for you.

I hope this helps.

Regards,
Rossen Hristov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or