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

Multiple Column Data Template with Different Binding

5 Answers 196 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ryan Overton
Top achievements
Rank 2
Ryan Overton asked on 06 Jan 2010, 05:48 PM

My problem is that I am wanting to use 1 data template for multiple colums in a gridview, but I want to bind the element in the data template to a different path.

In the example below I have a template that creates a checkbox.

<Grid.Resources> 
            <Style x:Key="CheckboxCellStyle" TargetType="{x:Type telerik:GridViewCell}">  
                <Setter Property="ContentTemplate">  
                    <Setter.Value> 
                        <DataTemplate> 
                            <CheckBox VerticalAlignment="Center" IsChecked="{Binding ????}" Click="CheckBox_Click" /> 
                        </DataTemplate> 
                    </Setter.Value> 
                </Setter> 
            </Style> 
</Grid.Resources> 

I want to bind the IsChecked property to the binded element in the data colulmn definition.

<telerik:GridViewDataColumn Header="Deleted" DataMemberBinding="{Binding Deleted}" CellStyle="{StaticResource CheckboxCellStyle}"></telerik:GridViewDataColumn> 
<telerik:GridViewDataColumn Header="Selected" DataMemberBinding="{Binding Selected}" CellStyle="{StaticResource CheckboxCellStyle}"></telerik:GridViewDataColumn> 


Can someone please help me find a solution to this problem?

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 08 Jan 2010, 09:41 AM
Hi Ryan ,

How about using an IValueConverter for the binding  and passing the column name as the converter parameter  ?

Let me know if you need a working example on that .

Greetings,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ryan Overton
Top achievements
Rank 2
answered on 08 Jan 2010, 01:58 PM
Hello Pavel,

A working example would be greatly appreciated.

Thank you,
Ryan Overton
0
Accepted
Pavel Pavlov
Telerik team
answered on 12 Jan 2010, 05:48 PM
Hello Ryan Overton,

As promised I am attaching a small example. While playing with your scenario I found a way to do this even without converter.
Hope it works for you!

Best wishes,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eric Belanger
Top achievements
Rank 1
answered on 02 Feb 2010, 06:27 PM
The problem with the sample you provided is that the TwoWay binding mode is not working.  I changed the OneWay binding to TwoWay and when i change a cell value, the value doesn't push back the value to the underlying model.

Is it something that is possible to do?
0
Pavel Pavlov
Telerik team
answered on 03 Feb 2010, 09:57 AM
Hello Eric Belanger,

Yes indeed , messing with the cell value  overrides the default binding logic of the cell. Unfortunately I can not think of a way to do this without explicitly specifying the property  to be edited either in XAML or in code.

There is a hacky solution - to handle to the click event of the checkbox and update the underlying business object in the event handler . However this would require reflection in the handler to obtain the property to be updated and set the value.  It becomes complicated and I am not sure it is a good way at all.

Best wishes,
Pavel Pavlov
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
Tags
GridView
Asked by
Ryan Overton
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Ryan Overton
Top achievements
Rank 2
Eric Belanger
Top achievements
Rank 1
Share this question
or