CellEditTemplate binding

2 posts, 0 answers
  1. Henry
    Henry avatar
    5 posts
    Member since:
    Jan 2013

    Posted 23 Jan 2013 Link to this post

    Hi

    I have a question on using the CellEditTemplate which has a TextBox in RadGridView.

    I have a RadGridView, one of its columns is created like this in cs file:

    gvColumn = new GridViewDataColumn();
    gvColumn.CellEditTemplate = (DataTemplate)grid.TryFindResource("TextBoxEditTemplate");
    gvColumn.DataType = typeof(string);
    gvColumn.DataMemberBinding = new Binding(...)

    In xaml file I define the template like this:

    <telerik:RadGridView.Resources>
                    <DataTemplate x:Key="TextBoxEditTemplate">
                        <TextBox Text="{Binding RelativeSource={RelativeSource Self}, Path=DataMemberBinding.PropertyPath}"/>
                    </DataTemplate>
    ...

    but the 'Text' of this text box is not bound to content of the cell, they are sperated, when user tries to edit, the cell's content is not
    in the TextBox, and vice versa.

    Thanks.

    Henry

  2. Henry
    Henry avatar
    5 posts
    Member since:
    Jan 2013

    Posted 24 Jan 2013 Link to this post

    I find the correct way to binding, it should be:

    <TextBox Text="{Binding

    RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:GridViewCell }}, Path=Value

    }"/>

    Thanks.

    Henry
Back to Top