Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1450
Databound EditorStyle and EditorType
posted

Hi there

I'm a bit stuck, finding a solution to our following use case. We have a list of items in a XamDataGrid and an item has a property, which determines what kind of editor should be used to input a value for a second property.

So if item.TypeData is "string", then the editor for Item.Value should be a XamTextEditor, if item.TypeData is "num", then the editor should be a XamNumericEditor, item.TypeData is "list" then the editor should be a XamComboEditor with a matching style (for stuff like ItemSource, DisplayMemberPath, ValuePath), and so on.

We fill a property called 'EditorStyle' depending on the property "TypeData" with the correct style in our object and try to bind it with a CellBinding. But this is only working, when the EditorType is set on the Field. (So for the whole column, not only the cell.) But if we try to use a XamTextEditor, when the Field.EditorType is set to another type than XamTextEditor, this obviously is not working.

                    <igDP:Field Name="CodeValue" >
                        <!--<igDP:Field.Settings>
                            <igDP:FieldSettings EditorType="{x:Type igEditors:XamComboEditor}" />
                        </igDP:Field.Settings>-->
                        <igDP:Field.CellBindings>
                            <igDP:CellBinding Property="IsReadOnly" Target="Editor" Binding="{Binding Path=DataItem.DisallowCodeValue}" />
                            <!--<igDP:CellBinding Property="ValueType" Target="CellValuePresenter" Binding="{Binding Path=DataItem.ValueType}" />-->
                            <igDP:CellBinding Property="Style" Target="Editor" Binding="{Binding Path=DataItem.EditorStyle}" />
                        </igDP:Field.CellBindings>
                    </igDP:Field>

Any idea how to achieve this?

Parents
No Data
Reply
  • 34430
    Offline posted

    Hello Andreas,

    I have been investigating into the behavior you are looking to achieve in this case, and I don’t believe the CellBinding that you have provided is doing what you think it is in this case. More specifically, the one targeting the Editor’s Style. This is going to target the Style of the Editor that is in the cell already, not the EditorStyle of the Field, and these are handled differently. Unfortunately, there does not exist a way to target the EditorStyle of the Field and bind that to a different value per cell.

    This is not to say that your requirement is not achievable, though. My best recommendation for you in this case is to use a TemplateField. There, you can define an EditTemplate and put all of the editors inside with a Visibility setting of Collapsed initially. The DataTemplate that you define has a Triggers collection that you can then bind to data item properties on, and then you can add Setters to make one of the editors that you add to the DataTemplate visible.

    I am attaching a sample project to demonstrate the above. I hope this helps you.

    Please let me know if you have any other questions or concerns on this matter.

    XDGDifferentEditorsPerCellDemo.zip

Children