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
From my testing it should. As long as the InitializeRecord event gets fired (which should be fired if the CellUpdated event gets fired) then the approach I suggested will change the editor of the field. I believe it should also work if the data gets updated in another way than through the cell, though I haven't tested this to verify.
I did achieve that behaviour using Datatriggers and styles. However when you update the data sometime the styles do not change.
would your method fix this issue?
Hello Murray,
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.
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
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>