Home Forums WPF controls Xceed DataGrid for WPF Adding a custom cell editor via code.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24480 |

    Hi all.
    In my grid the columns are dinamically added via code.
    How could I use a Custom cell editor for those columns? I.e: a slider?

    Thx for now

    Ricardo Dorta

    Imported from legacy forums. Posted by Ricardo (had 615 views)

    Xceed Support
    Member
    Post count: 5658

    You can add the column editors when you create the columns:

    Column myNewColumn = new Column();
    myNewColumn.CellEditor = xxx;

    Where xxx can be:

    this.Resources[ “myEditor” ] if the editor is present in the XAML resources
    OR
    myCellEditor where myCellEditor is a CellEditor that was created through code.

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

    User (Old forums)
    Member
    Post count: 23064

    it´s still not very clear.

    Let´s say that i have a slider.

    How would I add it as a CellEditor via C#?

    I mean, I know I need to use the CellEditor.EditTemplate property.
    But it expects a DataTemplate, how can i transform a Slider into DataTemplate?

    Thx for now.

    Ricardo Dorta

    Imported from legacy forums. Posted by Ricardo (had 373 views)

    Xceed Support
    Member
    Post count: 5658

    Normally, you would have to create you DataTemplate in XAML for this kind of scenarios (you can refer to the documentation on how to create your own CellEditors in XAML ).

    But there is an alternate way, that works through code… However, be aware that Microsoft has marked this way as “deprecated” in its documentation.

    DataTemplate myEditorTemplate = new DataTemplate();
    myEditorTemplate.VisualTree = new FrameworkElementFactory( typeof( Slider ) );

    CellEditorBindingExtension cellEditorBinding = new CellEditorBindingExtension();

    myEditorTemplate.VisualTree.SetBinding( Slider.ValueProperty, cellEditorBinding.ProvideValue( null ) );

    For further details, I recommend reading the SDK documentation on FrameworkElementFactory.

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

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