Hello,
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
https://stackoverflow.com/questions/17973652/xamdatagrid-selecteditems-empty-on-click-on-editable-cell?r=SearchResults&s=22|42.2433
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.
https://www.infragistics.com/community/forums/f/ultimate-ui-for-wpf/95531/xamcolorpicker-in-xamdatagrid---editmodeended-event-not-raised-if-cellclickaction-selectrecord
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?
Thanks
Niko
Hello Niko,
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.
Hello Andrew,
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?
Thank you for your update on this matter.
I am rather surprised that clicking / opening the drop-down of the XamColorPicker is not changing the ActiveDataItem. This leads me to believe that the issue might exist in the way that the XamColorPicker is placed in the XamDataGrid Field.
With the above said, you could use the Infragistics.Windows.Utilities.GetAncestorFromType method I provided to “force” activation of the record by setting the ActiveRecord property of the grid, but I feel that this should be happening automatically.
Can you please provide some more information on how exactly you are placing this in the XamDataGrid, as there are multiple ways this could be done?
I am still looking into the ActiveDataItem to solve the issue.
I have isolated the XamDatagrid and put into a testproject - see attachment.
If you start the program and then immediatly open the XamColorPicker dropdown, the ActiveDataItem is not set.
Please let me know if you can reproduce this behavior and how to fix it.
NikoActiveDataItemTest.zip
I have been investigating into your sample project, and I have found that it appears that the XamColorPicker is essentially “eating” the mouse-click when you click it, so it is never bubbling up to the CellValuePresenter / DataRecordPresenter in order to activate the record.
I have come up with a workaround to this that will work when simply clicking the XamColorPicker, in that if you handle the PreviewMouseDown event on the XamColorPicker in your cell and use the Utilities method mentioned above to set the ActiveRecord, you can ensure the ActiveDataItem is set.
I am attaching a modified version of your sample project to demonstrate. I hope this helps.
2476.ActiveDataItemTest.zip