Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1590
XamDatagrid and XamColorPicker: Keep SelectedDataItem
posted

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

Parents
No Data
Reply
  • 30890
    Verified Answer
    Offline posted

    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.

Children