Home Forums WPF controls Xceed DataGrid for WPF CellContentTemplateSelector – Binding issue

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • User (Old forums)
    Post count: 23064
    #23609 |

    I have a DTo that I’m using the data grid on that contains 2 related fields. The intent is to display a checkbox for the one field based on the value of the other.

    I have this working using a custom CellContentTemplateSelector. the issue I’m having is that when you check the checkbox the value is no longer being updated on the underlying DTO.

    Please advise to what I’ve done wrong, or what I’m missing…

    Here is my C# code for creating the Column and custom DataTemplateSelector.

    Thanks in advance…

    private void CreatePostColumn()
    Column postColumn = new Column();

    postColumn.FieldName = “Post”;
    postColumn.Title = “Post”;
    postColumn.CellContentTemplateSelector = new PostSelector();
    Binding binding = new Binding(“.”);
    binding.Mode = BindingMode.TwoWay;
    postColumn.DisplayMemberBinding = binding;

    return postColumn;

    internal class PostSelector : DataTemplateSelector
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    DataTemplate emptyTempate = new DataTemplate();
    MyDTO dto = item as MyDTO ;

    if (dto == null || dto.Status.Equals(StatusType.Success))
    return emptyTempate;

    DataTemplate checkboxTemplate = new DataTemplate();
    FrameworkElementFactory checkbox =
    new FrameworkElementFactory( typeof( CheckBox ) );
    checkboxTemplate.VisualTree = checkbox;

    return checkboxTemplate;

    Imported from legacy forums. Posted by Greg (had 2503 views)

    Xceed Support
    Post count: 5658

    The CellContentTemplate should not be used to attempt “modifying” the Cell’s Content…

    Effectivelly, the DataContext of the DataTemplate might be the “Content” but changes to the DataContext are not repercuted to the ContentProperty (it’s only the DataContext that changes)…

    This is the reason why we came up with the CellEditor.EditTemplate which should be using the “CellEditorBinding” Markup Extension to achieve the proper “edition” binding.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 352 views)

    User (Old forums)
    Post count: 23064

    thanks for the Feedback.

    What I need then is to be able to dynamically assign an EditTemplate based on the value of another cell on the same row. Do you have a C# code example of that. I’ll take a XAML example in the absense of a C# example.



    Imported from legacy forums. Posted by Greg (had 3598 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.