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
2090
XamDatagrid: Event after the multiple cell selection is finished
posted

Hello,

in a XamDatagrid I have following settings:

1. SelectedItemsChanged="Teameinteilung_SelectedItemsChanged"

2. XamDataGrid.FieldLayoutSettings: SelectionTypeCell="ExtendedAutoDrag"

The important scenario is the selection of multiple cells by keeping the mouse button down and drag over the needed cells.

I was expecting to get the callback Teameinteilung_SelectedItemsChanged only once, but it fires on every the selection of every single cell.

Is there an event that fires only after the cell selection and the mouse button up?

Thanks

Niko

  • 2680
    Offline posted

    Hi Niko,

    Thank you for posting to Infragistics Community!

    I have been looking into your question and what I can say is that this functionality is expected with “ExtendedAutoDrag” selection mode. To elaborate on why this is the case, imagine the “click”+”drag” actions – each drag down or up adds an item to the selection, however, each subsequent move could be the end of the selection operation. Thus, the SelectedItemsChanged is emitted. Consequently, there is not an alternative event to it.

    While I am not aware of the purposes of the SelectedItemsChanged event hanlder in your scenario, in case it is to access the selected items, what I can suggest is adopting the following “workaround”. Create a boolean flag indicating whether the selected items were changed and handle the PreviewMouseUp event of the grid. In case the flag is true, the selected items could be accessed via the SelectedDataItems property of the XamDataGrid. Please, check out this topic from our documentation for more details about how it works. Namely, the SelectedDataItemsScope property of the grid has to be set to other than “None” to be able to use the former.

    Also, in the PreviewMouseUp handler, the flag has to be reset to ‘false’.

      private bool selectedItemsChanged { get; set; }
    
            private void xdg_SelectedItemsChanged(object sender, Infragistics.Windows.DataPresenter.Events.SelectedItemsChangedEventArgs e)
            {
               this.selectedItemsChanged = true;
            }
    
            private void XamDataGrid_PreviewMouseUp(object sender, MouseButtonEventArgs e)
            {
                if(this.selectedItemsChanged && this.xdg.SelectedDataItems != null)
                {
                Console.WriteLine(this.xdg.SelectedDataItems.Length);
                }
                this.selectedItemsChanged = false;
            }
     

    If you require any further assistance on the matter, please, let me know.

    Best regards,
    Bozhidara Pachilova
    Associate Software Developer