hello:
i am trying to host a custom control in a xamdatagrid editor using the hostanyobject solution provided by infragistics blogs. All works fine in a normal edit solution using the following binding
SelectedItem="{Binding DataRecord.DataItem.PlatformProjectPayrollClass,RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type igDP:DataRecordPresenter}},Mode=TwoWay"
However when I try and use the same binding in an add row the binding never persists. Im assuming this is because the DataRecord has not been updated until it is in the list. How would I go about having something like a list in the addrow, and have it persist the list selected value down?
Attached is a basic sample although it still has issues. One new one, is that the button to add a row is not working in this sample but it does work in my app. Also, I haven't fully tested the custom control I quickly wrote and the value-text pass through..
Inheritting from YOUR ValueEditor is not an option as we have some controls that we need that already inherit from something else. You really should have an IValueEditor interface and the grid should only be interacting through that interface, not a base class, and then others could implement that interface in their custom controls.
There are a few ways to implement custom functionality in a cell. You can provide a DataTemplate for a CellValuePresenter. The content can be anything – a TextBox, a UserControl, etc. You can also implement your own derivation of a ValueEditor class as well. This involves a little more work.
It’s hard to fix the problem you are having without being able to test the code and XAML. Is there a way you could create a WPF sample with one of your custom controls so I can see how you are tackling this? Or, you could describe what the end result you are looking for for a cell in the grid and I would create something that would implement custom functionality in the way that I would approach the required specification.
It's a lot of code to review and no easy way to break it out. Basically, grids with only text, numeric, and date pickers only get you so far. We need lookups. So I have a custom lookup editor control. Clients also just don't like the way your editors (numeric,masked, date) work and so all the other non-text cells use our own digits editor.
If in add mode, the user MANUALLY changes a text column FIRST, add works great because all the grids events, EnterEditMode, CellChanged,RecordAdding, RecordAdded, etc all fire as soon as the user types the first character into that texteditor based cell.
But if the user types a character into one of my custom controls, nothing fires. In a way this makes sense since it's my own custom control embedded in the grid. But Infragistcs doesn't provide any way for me to make my custom control more grid friendly. Why is FieldSetting.Editor insist on something inheriting from Infragistics.ValuesEditor??? Why is this not an interface that I could implement in my own custom control?
And if a user changes a value in my custom control first, when my custom event fires where I would go move the value into the new underlying business object, it's not there since the grid hasn't done any of its stuff yet.
A solution to the following question would be most helpful:
Question: Assuming the grid is NOT enabled to immediately always show an add row, then when the user presses a button and I do set the properties for that add row to show up, then how can I ALSO PROGRAMMATICALLY get the grid to REALLY put that row into add mode and create the underlying objects. I would expect all those events, RecordAdding, RecordAdded, etc to fire when I programmatically do "something".
Is the underlying data model using ObservableCollection? If so you can listen to changes to the collection with a CollectionChanged handler.
As far as having the custom changes you've added work seamlessly, I would be willing to review your code to see what is going on and see how to best solve these issues. Is there any way you could extract your code into a simple WPF sample. This would be an ideal way to solve these issues as well as gete the code to me.
Thank you!
I'm having this very same issue.
I have a XamDatGrid, ALL the cells are hosting custom editors. For EDITTING purposes, everything "almost" works. The data is getting populated into the control from the underlying custom business object. However, changes in the custom editor controls are not getting bound back to the underlying business object. So I've had to hook into the custom editors value changed events to detect data entry changes to move that change into the underlying business object.
Now when ADDing records, it's worse. Since all of the cells are custom editors, NONE of the grids events are firing like CellChanged,EnterEditMode,RecordAdding,RecordAdded,RecordUpdated, etc.
So when my custom editor value changes event fires, while the ActiveCell will have it's record property populated, the grid's record property colllection is still empty, and the underlying business object has NOT yet been created. And even worse, properties are read only so I don't see any way to add the record object myself or instantiate and set the new business object.
I even tried sending commands to go into edit mode, accept changes, go back into edit mode, etc, but none of the events fire and no internal XamDataGrid logic seems to be firing.
1) If I just add my "new" empty business object to an observable collection, how can I get the grid to indicate that any given object row is an ADD row?
2) How can I programmatically force the grid into add mode that creates the underlying datarecord and business object BEFORE the user had even made the first change?
It seems that normally, the grid, when displaying an add row, doesn't create the underlying objects until the user changes a value in at least one cell. But now that I'm using custom editors, that logic never fires.