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

ConvertBack not called

4 Answers 367 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tommaso
Top achievements
Rank 1
Tommaso asked on 18 Aug 2010, 08:41 AM
Hello,
We are currently evaluating WPF controls for use in our applications.
Currently, we use plain WPF Datagrid with a lot of converters for string representation (non-edit mode) and parsing (edit mode).
We would like to re-use them when it is possible, but we have problems: despite what I read in the documentation, the following code

<telerik:GridViewDataColumn.CellEditTemplate>
                    <DataTemplate>
                            <TextBox Text="{Binding Path=., Mode=TwoWay, Converter={StaticResource NamespaceConverter}}" />
                    </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>

fails to call ConvertBack on our converter, calling instead a RadGridView internal functions and giving an ArgumentNullException (Parameter name: conversionType) in Telerik.Windows.Controls.GridView.dll!Telerik.Windows.Controls.GridView.GridViewCell.TryConvertValueFromEditor


The equivalent WPF code

<DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Path=., Mode=TwoWay, Converter={StaticResource NamespaceConverter}}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>

works without errors.
Are we doing something wrong? How do you use converters in a grid?
Thanks,
Lorenzo

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 18 Aug 2010, 12:54 PM
Hi Lorenzo Dematte',

 
I have tried to reproduce your problem but everything works as expected on my side and the ConvertBack method of the class implementing IValueConverter is called. So, in order to be able to provide you with an appropriate solution, I would need more details about your project, the converter implementation and the type of data supplying the grid.

Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tommaso
Top achievements
Rank 1
answered on 18 Aug 2010, 02:12 PM
Strange...
I have a converter in the static resources

<Window.Resources>
        <local:FullNameConverter x:Key="NamespaceConverter" />
    </Window.Resources>

And the grid is defined as

<telerik:RadGridView x:Name="RadGridView1" ItemsSource="{Binding}" Margin="0"
                          RowIndicatorVisibility="Collapsed" IsReadOnly="False"
                          AutoGenerateColumns="False" CanUserFreezeColumns="False"
                          CanUserResizeColumns="False" DataContext="{Binding}">
            <telerik:RadGridView.RowStyle>
                <Style TargetType="telerik:GridViewRow">
                    <Setter Property="MinHeight" Value="40"/>
                </Style>
            </telerik:RadGridView.RowStyle>
             
            <telerik:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn />
                <telerik:GridViewDataColumn Header="Name" Width="*">
                    <telerik:GridViewDataColumn.CellTemplate>
                    <DataTemplate>
                            <TextBlock Text="{Binding Path=FullName}" />
                    </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                    <DataTemplate>
                            <TextBox Text="{Binding Path=., Mode=TwoWay, Converter={StaticResource NamespaceConverter}}" />
                    </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>

It is bound to a collection of data structures, which contain a pair of strings. The converter "Convert" method concatenates the strings, the "ConvertBack" parses the concatenated string and divides it into the two fields. I know there are more convenient ways of doing this, it was only a test with a simple converter..

I can send you the complete simple application, if you want.
Should I open a ticket?

Cheers,
Lorenzo
0
Accepted
Maya
Telerik team
answered on 18 Aug 2010, 03:31 PM
Hello Lorenzo,

The fact that the ConvertBack() method of the Converter is not called is caused by the way the Binding is created. As the TextBox is not bound to a certain property, but the Text is defined as: 

<TextBox Text="{Binding Path=., Mode=TwoWay, Converter={StaticResource NamespaceConverter}}" />

However, following up your scenario, you may use another approach and expose a new property that implements the logic inside the concatenated field - FullName. 
I am sending you a sample project illustrating the proposed solution.
 


Kind regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Tommaso
Top achievements
Rank 1
answered on 18 Aug 2010, 05:38 PM
That's exactly what I did in the end, and I agree that this is the best solution.
The only thing that bugs me is that in WPF DataGrid it works...
Anyway, no problem, this was only an excercise to see if converters work. I will get back to you when (and if!) we end up in a scenario that really needs a converter.
Thank you,
Lorenzo
Tags
GridView
Asked by
Tommaso
Top achievements
Rank 1
Answers by
Maya
Telerik team
Tommaso
Top achievements
Rank 1
Share this question
or