Home Forums WPF controls Xceed DataGrid for WPF Strange behaviour after choosing SelectionRow

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

    Hi,

    I have CustomDataGrid, with CustomRow and CustomCell as well. I need it because i use custom cell editors, for each data type. When i am changing the selection between rows, cell editors appears correctly, but when I choose InsertionRow as current, after that I click on one row, and again click on the another then i get wrong cell editors, no matter which one row it is, it always appears in second row, after InsertionRow..

    This is my code, i use only C#, and i wish to use only C#:

    —————This my EditControlSelectorClass——————————–

    public static class EditControlSelector
    {
    public static void CreateCellEditor(Column __column, object __item)
    {
    //object type = __column.CellContentTemplate.DataType;

    __column.CellEditor = new CellEditor();
    __column.CellEditor.EditTemplate = new DataTemplate();
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();

    if (__item is String)
    {
    __column.CellEditor.EditTemplate.VisualTree = new FrameworkElementFactory(typeof(StringEditControl));
    __column.CellEditor.EditTemplate.DataType = typeof(string);
    __column.CellEditor.EditTemplate.VisualTree.SetBinding(StringEditControl.TextProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }
    else if (__item is Boolean)
    {
    __column.CellEditor.EditTemplate.VisualTree = new FrameworkElementFactory(typeof(BoolEditControl));
    __column.CellEditor.EditTemplate.DataType = typeof(bool);
    __column.CellEditor.EditTemplate.VisualTree.SetBinding(BoolEditControl.IsCheckedProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }
    else if (__item is Int32)
    {
    __column.CellEditor.EditTemplate.VisualTree = new FrameworkElementFactory(typeof(IntEditControl));
    __column.CellEditor.EditTemplate.DataType = typeof(int);
    __column.CellEditor.EditTemplate.VisualTree.SetBinding(IntEditControl.TextProperty , (BindingBase)myCellEditorBinding.ProvideValue(null));
    }
    }
    }

    ———–I use it here:————————————————————

    class ContentControlSelector : DataTemplateSelector
    {
    private Column _Column;
    public Column Column
    {
    get { return _Column; }
    set { _Column = value; }
    }

    public ContentControlSelector(Column __col) : base()
    {
    this.Column = __col;
    }

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
    DataTemplate dt = null;

    if (item is String)
    {
    dt = new DataTemplate();
    dt.VisualTree = new FrameworkElementFactory(typeof(StringControl));
    dt.DataType = typeof(string);
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();
    dt.VisualTree.SetBinding(StringControl.ContentProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));

    }
    else if (item is Int32)
    {
    dt = new DataTemplate();
    dt.VisualTree = new FrameworkElementFactory(typeof(IntControl));
    dt.DataType = typeof(int);
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();
    dt.VisualTree.SetBinding(IntControl.ContentProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }
    else if (item is Boolean)
    {
    dt = new DataTemplate();
    dt.VisualTree = new FrameworkElementFactory(typeof(BoolControl));
    dt.DataType = typeof(bool);
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();
    dt.VisualTree.SetBinding(BoolControl.IsCheckedProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }
    else
    {
    dt = new DataTemplate();
    dt.VisualTree = new FrameworkElementFactory(typeof(CustomDataCell));
    CellEditorBindingExtension myCellEditorBinding = new CellEditorBindingExtension();
    dt.VisualTree.SetBinding(CustomDataCell.ContentProperty, (BindingBase)myCellEditorBinding.ProvideValue(null));
    }

    EditControlSelector.CreateCellEditor(Column, item);
    return dt;
    }

    ————-Above class I finally use here, in main class, where CustomDataGrid is stored as _Grid————————————————-

    foreach (Column col in _Grid.Columns)
    {
    col.CellContentTemplateSelector = new ContentControlSelector(col);
    }

    Sorry for a lot of lines of code, but I hope it will help you to find a solution:)

    Cheers,
    Majkel

    Imported from legacy forums. Posted by Michal (had 767 views)

    User (Old forums)
    Member
    Post count: 23064

    Dear WPF-SupportTeam@Xceed

    I have a similar problem.

    I also use a CellContentTemplateSelector to change the CellContentTemplate on data provided by my own QueryCell-class.
    This QueryCell data is some kind of generic cell, which comes from a calcuation engine. The values could probably be a yes/no (= checkbox) or a list of values (Combolist) or a editable list of value (=ComboBox with free textedit) or ….
    So I not only change some background colors, but I change complete cell layout AND I will get some lists of possible valid valueitems for THIS cell to select in my edit step. These lists can change per row !!

    So your CellContentTemplate works fine and my generic QueryCellData will be displayed as I expect, depending on my real own provided QueryCell data.

    Until now, I have only found some concepts, to change the EditTemplate on a per Column or per DataTypebasis. But both approaches won’t fit my requirements, because even on a per Column EditTemplate, my defaultlists for a combobox will change for each row.

    So I think majkez has the same problem and above workaround could not work well, because it is not predictable, that immediatly before start edit the CellContentSelector will be invoked to change CellEditTemplate of the complete column to fit to my requested QueryCell.

    Do you have any ideas, how to solve this issue ?

    Thanks for any solution
    Dietmar

    Imported from legacy forums. Posted by Dietmar (had 3001 views)

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