Home Forums WPF controls Xceed DataGrid for WPF Cannot bind to user control cell editor

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

    I have created a User Control with 2 verticle textboxes. And want to place this in a cell for editing. I still cannot get the cell editor to bind.

    What appears in the output window is always this…

    System.Windows.Data Error: 12 : Cannot get ‘DistinctValues’ value (type ‘ICollection’) from ‘ParentColumn’ (type ‘Column’). BindingExpression:Path=ParentColumn.DistinctValues.Count; DataItem=’ColumnManagerCell’ (Name=”); target element is ‘ColumnManagerCell’ (Name=”); target property is ‘NoTarget’ (type ‘Object’) TargetInvocationException:’System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. —> System.NotSupportedException: Automatic filtering can only be used if the grid’s data source is a DataGridCollectionView or DataGridCollectionViewSource.
    at Xceed.Wpf.DataGrid.Column.get_DistinctValues()

    I am using a DataGridControl, not a DataGridCollectionView or DataGridCollectionViewSource.

    I had asked this question weeks ago and still haven’t had any success in binding. The User Control called local:StackedAmountControl;

    How do I bind this column cell to the Dependency property I defined for it?

    Imported from legacy forums. Posted by Shelley (had 6439 views)

    User (Old forums)
    Member
    Post count: 23064

    I am getting the Same issue did you ever get this fixed?

    Imported from legacy forums. Posted by Dan (had 717 views)

    User (Old forums)
    Member
    Post count: 23064

    No, I never got a response. I would really appreciate some help with this, I am unable edit a column thats set up with 2 verticle textblocks. I can bind the data ok, but cannot edit it.

    Could someone revisit this with me?

    Thanks
    Shelley

    Imported from legacy forums. Posted by Shelley (had 486 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Shelley,

    The error posted is not related to anything that refers to custom CellEditors. You will need to provide more details such as the XAML for your editor, the column definition and any other relevant code.

    This way, somebody might be able to figure what the issue is.

    Thanks.

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

    User (Old forums)
    Member
    Post count: 23064

    This is the data I have…

    Left.Static.Amount (a double)
    Left.Dynamic.Amount (a double)

    I want to have a column cell with 2 vertical stack panels. This Cell Template shows them correctly…

    <DataTemplate x:Key=”AmountCellTemplate”>
    <StackPanel Orientation=”Vertical” Style=”{StaticResource ComboBoxStackPanel}” >
    <TextBlock Text=”{Binding Path=Static.Amount}” >
    <Separator Style=”{DynamicResource SimpleSeparator}”/>
    <TextBlock Text=”{Binding Path=Dynamic.Amount}” />
    </StackPanel>
    </DataTemplate>

    However I cannot setup a CellEditor Binding so the data can be edited.

    For instance, this doesn’t work…

    <xcdg:CellEditor x:Key=”AmountCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <StackPanel Orientation=”Vertical” >
    <TextBox Text=”{Binding Path=Static.Amount}” />
    <Separator Style=”{DynamicResource SimpleSeparator}”/>
    <TextBox Text=”{Binding Path=Dynamic.Amount}” />
    </StackPanel>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>

    neither does this…

    <xcdg:CellEditor x:Key=”AmountCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <StackPanel >
    <TextBox Text=”{xcdg:CellEditorBinding}” />
    <Separator Style=”{DynamicResource SimpleSeparator}”/>
    <TextBox Text=”{xcdg:CellEditorBinding}” />
    </StackPanel>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>

    I was last told instead to make a UserControl with 2 textboxes with a DependencyProperty and bind to that.

    So as of now, this is my User Control…

    public class MyControl : UserControl
    {
    public MyControl()
    {
    //Control has 2 textboxes
    TextBlock textStatic = new TextBlock();
    TextBlock textDynamic = new TextBlock();

    Binding bindingStatic = new Binding();
    bindingStatic.Source = textStatic;
    bindingStatic.Path = new PropertyPath(“Static.Amount”);
    bindingStatic.Mode = BindingMode.TwoWay;

    Binding bindingDymanic = new Binding();
    bindingDymanic.Source = textStatic;
    bindingDymanic.Path = new PropertyPath(“Dynamic.Amount”);
    bindingDymanic.Mode = BindingMode.TwoWay;

    }

    public double Left
    {
    get
    {
    return (double)GetValue(LeftProperty);
    }

    set
    {
    SetValue(LeftProperty, value);
    }
    }

    // Using a DependencyProperty as the backing store for Left.
    public static readonly DependencyProperty LeftProperty =
    DependencyProperty.Register(“Left”, typeof(double), typeof(MyControl), new UIPropertyMetadata(null));
    }

    and this is the Cell Binding I set up to bind to MyControl, that still doesn’t work….

    <xcdg:CellEditor x:Key=”LeftCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <local:MyControl Left=”{xcdg:CellEditorBinding}”/>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    </xcdg:CellEditor>

    Do you see what I am missing?

    Let me know what other information I can provide.

    Thanks,
    Shelley

    Imported from legacy forums. Posted by Shelley (had 691 views)

    Xceed Support
    Member
    Post count: 5658

    Your bindings in your UserControl are not attached to anything. Also, you are not adding the textboxes as childs of the UserControl, they will therefore never appear. (however, the CellEditor definition is OK ).

    My suggestion is to use XAML to define the UserControl’s UI, it is at the same time simpler and more WPF oriented:

    in the UserControl1.xaml file:

    <code>
    <UserControl (lots of auto generated stuff) >
    <StackPanel>
    <TextBox Text=”{Binding Path=Left.Static.Amount}” />
    <TextBox Text=”{Binding Path=Left.Dynamic.Amount}” />
    </StackPanel>
    </UserControl>
    </code>

    And then, in the UserControl1.xaml.cs:

    <code>

    public partial class UserControl1 : UserControl
    {
    public UserControl1()
    {
    //add this to the default ctor
    this.DataContext = this;

    this.InitializeComponent();
    }

    //define your Left property here.
    }

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

    User (Old forums)
    Member
    Post count: 23064

    Thanks, I implemented your suggestion, but I am still not able to edit the textboxs.

    How does the UserControl1 get instantiated? I put a break at the constructor and it is never called, so I’m missing that connection. It’s only currently refered to in the CellEditor definition.

    Also, how should I define the Left property? Should I instead define 1 to access the static double and another to access the dynamic double?

    Shelley

    Imported from legacy forums. Posted by Shelley (had 458 views)

    Xceed Support
    Member
    Post count: 5658

    In order to be a binding target, a property need to be a DependencyProperty. You should simply declare your property as you would do for any other dependency property.

    If you user control is never instantiated, it is possibly because:

    1. Editor is never displayed, check your CellEditorDisplayConditions and your EditTriggers.
    2. Editor was not assigned to the column. Check if it is properly assigned.

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

    User (Old forums)
    Member
    Post count: 23064

    I have tried these suggestions, and still no cell editor. The control is not being instantiated.

    My UserControl is called AmountsControl.

    This is how I define my cell editor;

    <xcdg:CellEditor x:Key=”LeftCellEditor”>
    <xcdg:CellEditor.EditTemplate>
    <DataTemplate>
    <local:AmountsControl Amount=”{xcdg:CellEditorBinding}”/>
    </DataTemplate>
    </xcdg:CellEditor.EditTemplate>
    <xcdg:CellEditor.ActivationGestures>
    <xcdg:KeyActivationGesture Key=”Up”/>
    <xcdg:KeyActivationGesture Key=”Down”/>
    </xcdg:CellEditor.ActivationGestures>
    </xcdg:CellEditor>

    This is how my editor is assigned to the column;

    <xcdg:Column
    FieldName =”Left”
    Title=”Left”
    Width=”70″
    CellEditor=”{StaticResource LeftCellEditor}”
    CellContentTemplate=”{StaticResource AmountCellTemplate}”
    />

    This is my dependency property definition;

    public static readonly DependencyProperty AmountProperty =
    DependencyProperty.Register(“Amount”, typeof(double), typeof(AmountsControl), new UIPropertyMetadata(null));

    I’ve been checking and trying different assignments for CellEditorDisplayConditions and EditTriggers, both on the xcdg:DataGridControl and on the xcdg:Column. Nothing will bring up the cell editor.

    Do you see anything that is missing?

    Shelley

    Imported from legacy forums. Posted by Shelley (had 773 views)

    User (Old forums)
    Member
    Post count: 23064

    Since I haven’t got a response to this and have tried everything, including all your suggestions, could you point me in the direction of a sample of code or a working example?

    I haven’t found any examples in any of the WPF/XCeed samples or documentation for doing this.

    I have checked both CellEditorDisplayConditions and Edit Triggers, and my editor is assigned correctly to the cellEditor property of the column, but still remains nonfunctional.

    Thanks
    Shelley

    Imported from legacy forums. Posted by Shelley (had 7261 views)

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