I have a data grid that uses combo boxes for the user to select an object.
My problem is that the combo boxes are populated with what is currently available ( date / level related) which is fine while filling out the current day but if you look at historic data the combo box does not always contain the items that were selected in the past. Which means they don't display the label all you see is a reference to the object.
I thought the solution to this would be to change the editor style in historic data to a text box ( editing no longer needed) and show just the item that was selected.
However because I am working with objects I can't get them to display properly. Changing the editor style to a texteditor is fine but I need the to display a property of the object in the texteditor not the object.
In the combobox the DisplayMemberPath handles this. But in the textbox i can't get it to display the Object.Name rather than Object
Can anyone suggest a way to handle this issue?
Thanks
Murray
Hello Murray,
Does the column that shows the historic data only ever display a text box or will it also sometimes need to display a combo box? If you only need to display the text box then one way to go about this would be to use an UnboundField and set up the grid to display a complex property:
<http://help.infragistics.com/NetAdvantage/WPF/Current/CLR4.0/?page=xamDataPresenter_Displaying_a_Complex_Property_XAML.html>
If this doesn't work, or if it doesn't match what you need to accomplish, please provide me with a few more details about the data you want to display. If possible, please include a small project that demonstrates the issue.
Hi Jason
Thanks for the link
It shows how to display the properties of the object. Which I knew. What I am struggling with is if you take that example and then you wanted in edit mode to display a combo box how do you do that?
It would need to switch back to the text box displaying the complex property after edit
do you know how that can be done?
regards
OK So i have worked out this:
I can set a data trigger that sets the control template style on the value of a property in the record. This means I can set the the grid to display a textbox for historic data like this
<DataTrigger Binding ="{Binding DataItem.Status}" Value="1"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type DataPresenter:CellValuePresenter}"> <TextBlock Text="{Binding DataItem.SourceLocation.Name}"/> </ControlTemplate> </Setter.Value> </Setter> </DataTrigger>
The problem I am having with this solutions is that it works most of the time.
Sometimes the styles only half change leaving me a locked cell with no ability to edit.
Can you see any issues with what i am doing?
thanks
I'm still not entirely clear on what sort of data you want to display, however it sounds like the main issue here is that you would like be able to display different editors in a column based off of the value of another cell in the record.
If this is the case, the best way to do this is to use the XamDataGrid's InitializeRecord event, which fires every time a cell's value is updated. Then, check the value of your Status cell for the record that has been changed and set the EditorType and EditorStyle for the Field that you want to change.
I've attached a small sample that demonstrates this approach. Please let me know if this is what you needed and if I can be of any further assistance.
I just wanted to check in and see if you have had a chance to come back to this issue and if you needed any further assistance with this matter.
I was still unable to get the behaviour of the grid working correctly.
Unfortunately I am off on another project for the next month and don't have time to keep working on this.
When I get back to it I will probally be in touch
thanks for the follow up
Regards
Do you have any further questions or concerns about switching the editors for a cell in the XamDataGrid based off of other data in the record?
If I'm understanding this issue correctly, this comes from the fact that XamDataGrid determines the editor to show based off of the EditorType or the EditorStyle, with the EditorStyle overriding the EditorType. If you look at my sample I account for this by setting the EditorStyle to null whenever I change the EditorType to a XamTextEditor. You should also be able to replace the XamComboEditor style with a XamTextEditor style if you need to.
This is still giving me problems.
It may have solved one of the issues, as it it does seem to switch better now. However only if you don't have an editor style set on the field. And if you do that then there is no combo box available in the add new record row.
I will play around more and see if i can get it to work. Once I have done more testing I will post back