Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Setting column cell editor affects other columns?

Sort Posts: Previous Next
  •  06-27-2007, 11:47 AM Post no. 8578

    Setting column cell editor affects other columns?

    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
  •  07-02-2007, 11:03 AM Post no. 8579 in reply to 8578

    Re: Setting column cell editor affects other columns?


    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
  •  07-10-2007, 12:50 PM Post no. 8580 in reply to 8579

    Re: Setting column cell editor affects other columns?

    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
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.