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?
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
Hi AndrewThank you very much for your detailed answer and the sample. It works fine and i can adapt it to our solution.But i have a question about some improvements. On the XamComboEditor we use the properties "ValuePath" and "DisplayMemberPath" to translate a Listvalue from "x" to "x | LocalizedDescription". And if i use your sample as is, the XamDataGrid shows the values as "x" instead of "x | LocalizedDescription", because we only have that definded for the EditTemplate and the DisplayTemplate is empty. Only if the user clicks in the cell and starts the EditMode, he can se the correct list value. So i just defined the same DataTemplate in the DisplayTemplate property of the TemplateField and adjusted some little stuff. Now the XamDataGrid is showing the correct "translated" value description.But to dropdown the list of the XamComboEditor, the user have to click twice on the cell. First time to enter EditMode, second time to dropdown the list. While on the other column, where there is a "normal" XamComboEditor in the column, he only has to click once.I hope it's understandable, what i mean... But do you have any idea how to improve this too?Regards
In order to not have to click the cell multiple times, I would recommend utilizing the EditModeStarted event of the XamDataGrid. This will allow you to catch when you start edit mode on the TemplateField, and you can utilize the Infragistics.Windows.Utilities class to get your underlying “actual” editor within the EditTemplate. From there, you can open the drop-down of the XamComboEditor by setting its IsDropDownOpen property to true or focus your XamNumericEditor or XamTextEditor.
I am attaching a sample project to demonstrate the above.
5633.XDGDifferentEditorsPerCellDemo.zip
Hello AndrewSorry for the late reply, but we had other important stuff.I tried your solution, and it does work fine. But only, when there is no validation or the Property 'SupportDataErrorInfo' on 'FieldLayoutSettings' is set to 'None'.So the user selects in the DropDown on the first field, a value which renders the second field as not-optional, the showing of the Highlight and/or ErrorIcon breaks the input focus again. I tried a lot of things, but i'm stuck again.
Can you help with this too?Regards
Would it be possible for you to please modify the sample project I sent you such that it reproduces this behavior you are seeing or provide an isolated sample of your own that shows the behavior? I am not entirely sure what exactly to change in the sample to reproduce the exact behavior you are seeing?
Hello AndrewThank you for your feedback.I modified your sample, so it shows the behavior i was writing about. It's a really simple mock-up implementation, but shows exactly my issue.At runtime, change any ID to "11". (Preferably on a List Item.) And press "TAB" to switch the keyboard focus to the next column "Thing". When the validation kicks in, the focus is not on the editor anymore.
Regards
XDGDifferentEditorsPerCellDemo2.zip
I am unsure why at the moment, but it appears that the code that you replaced where the exact editor type is checked for the TextEditorBase is actually the culprit here. The Dispatcher.BeginInvoke code running at DispatcherPriority.ApplicationIdle also appears to be necessary for the focus to happen, as the editor instance needs to actually be created. The only editor that is known before the cell is in edit mode is the TemplateEditor, as the EditTemplate appears to be dynamically loaded.
Strangely, if I surround the textEditorBase.Focus() code in a Dispatcher.BeginInvoke action, this works for the XamTextEditor cells, but not the combo or numeric editor ones. I would recommend continuing to use the code that checks the exact editor type in this case.
Hi AndrewI had time to look at this again and I think I found the problem with my solution.
The big issue was getting the "to be focused editor" by type, instead of the name. Because of this, I only got always the same editor in the TemplateEditor, which was the first one defined in the XAML.I reworked the sample, and like this, it works as expected. Also with the Office2013 theme added.
3858.XDGDifferentEditorsPerCellDemo2.zip