Home Forums WPF controls Xceed DataGrid for WPF Setting column cell editor affects other columns?

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

    I want the cell editor for one of the columns in a data grid to be a combo box. When I set the cell editor for the column (“MyField”), I get the desired behavior for that column, however, another column (“MyOtherField”) in my grid (the only other editable column with the same data type, string) also uses the combo box editor. I want “MyOtherField” to retain the default text editor. Here’s the method I use to set the editor:

    private void InitializeEditor()
    {
    MyDataSet dataSet = this.GetMyDataSet();
    DataTemplate template = new DataTemplate();
    FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ComboBox));
    factory.SetValue(ComboBox.ItemsSourceProperty, this._choices);
    CellEditorBindingExtension binding = new CellEditorBindingExtension();
    factory.SetValue(ComboBox.SelectedValueProperty, binding);
    template.VisualTree = factory;

    Column column = this._gridControl.Columns[“MyField”];
    column.CellEditor.EditTemplate = template;
    }

    How do I set the editor only for the column “MyField”? Thanks.

    Regards,

    Mark

    Imported from legacy forums. Posted by Mark (had 618 views)

    User (Old forums)
    Member
    Post count: 23064

    Try this:

    Column column = new Column();
    column.CellEditor.EditTemplate = template;
    column.FieldName = “MyField”;

    this._gridControl.Columns.Add(column);

    Should work, i did not test it though. Hope its bug free 🙂 I do those things in XAML usually.

    Hth
    Silas

    Imported from legacy forums. Posted by Ralf (had 289 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks, Silas.

    It seems all columns share the same cell editor, so changing the template on one affects the others. The solution I came up with is:

    private void InitializeEditor()
    {
    MyDataSet dataSet = this.GetMyDataSet();
    DataTemplate template = new DataTemplate();
    FrameworkElementFactory factory = new FrameworkElementFactory(typeof(ComboBox));
    factory.SetValue(ComboBox.ItemsSourceProperty, this._choices);
    CellEditorBindingExtension binding = new CellEditorBindingExtension();
    factory.SetValue(ComboBox.SelectedValueProperty, binding);
    template.VisualTree = factory;

    Column column = this._gridControl.Columns[“MyField”];
    CellEditor cellEditor = new CellEditor();
    cellEditor.Template = template;
    column.CellEditor = celleditor;
    }

    The important thing here is to create a new CellEditor and assign it to the column, rather than modifying the existing CellEditor.

    Thanks,

    Mark

    Imported from legacy forums. Posted by Mark (had 3924 views)

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