when a XamColorPicker is used as editor inside a XamDatagrid I have a problem to keep the SelectedDataItem.
Its a very similar question to the behavior of the edittors which can be solved by using the event EditModeStarting
Is there a similar way to deal with XamColorPicker inside a XamDatagrid? Its neccessary to keep the SelectedDataItem in place during and after setting the new color. So far I found only this posting.
The event DropDownOpening of the XamColorPicker does not know anything about the hosting XamDatagrid (as far as I see it).
Is there a different way to keep the SelectedDataItem alive during editing in XamColorPicker?
I have been investigating into the behavior you are looking to achieve to retain the SelectedDataItem with the XamColorPicker in the XamDataGrid. Allow me to preface this by saying that this is expected. The selection in the XamDataGrid is cleared when you go into edit mode, but the ActiveDataItem property will remain as the item represented by the row that you are in edit mode on. If possible, you may want to consider using this instead.
With the above said, if you are looking to get to the record, the underlying data item, and the grid from the XamColorPicker in this case, I would recommend utilizing the Infragistics.Windows.Utilities class and its static GetAncestorFromType method. Using this method, you can get the CellValuePresenter ancestor of the XamColorPicker, and from the CellValuePresenter, the grid and the record that the cell presented is in. From the record, you can also get the underlying data item. Here is some sample code you may be able to use for this, where “picker” is your XamColorPicker:
var cellPresenter = Infragistics.Windows.Utilities.GetAncestorFromType(picker, typeof(CellValuePresenter), false) as CellValuePresenter;
var record = cellPresenter.Record as DataRecord;
var grid = cellPresenter.DataPresenter as XamDataGrid;
Please let me know if you have any other questions or concerns on this matter.
I was looking into the ActiveDataItem as well. It should fit all requirements.
The XamDatagrid contains beside other read only fields a XamNumericEditor and XamColorPicker. Editing the XamNumericEditor works fine: ActiveDataItem is set correctly.
When I open the colorpicker dropdown the ActiveDataItem does not change - thats the only problem left.
Is the suggested way to use the code behind you posted?