locked
WPF - Datagrid - Multi-Row selection deselected upon context menu on RowHeader RRS feed

  • Question

  • Hi,

    I have a CustomDataGrid control (extends DataGrid) and experience below issue.

    - Select two rows in DataGrid (continuous selection)

    - Right mouse click on RowHeader that display context menu (at this point grid retains the multi-select)

    Override DataGrid.OnRightMouseButtonUp and grid.SelectedItems has all selected rows.

    -When context menu get displayed it only select the current row and multi-select is not retained.

    Override DataGrid.OnContextMenuOpening and grid.SelectedItems has two rows before the call to base.OnContextMenuOpening and only one row after this call (this is current row on which right mouse click was performed).

    Any idea how to fix this or if this is a bug in DataGrid any known workaround available to resolve this issue?

    Thanks in advance.

    Thursday, June 2, 2011 4:45 PM

Answers

  • Hi Muthu Nagarajan,

    I think this is an expected behavior. No only mouse left-click but also right-click could select an row.

    If you don't want the row to be selected on mouse right-click, you can subscribe to the corresponding mouseup event and set e.Handled to True to block the mouse event.

    If you still have any questions or concerns about this issue, please feel free to let me know.

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Min Zhu Thursday, June 9, 2011 3:43 AM
    Monday, June 6, 2011 8:20 AM

All replies

  • Hi Muthu Nagarajan,

    I think this is an expected behavior. No only mouse left-click but also right-click could select an row.

    If you don't want the row to be selected on mouse right-click, you can subscribe to the corresponding mouseup event and set e.Handled to True to block the mouse event.

    If you still have any questions or concerns about this issue, please feel free to let me know.

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Min Zhu Thursday, June 9, 2011 3:43 AM
    Monday, June 6, 2011 8:20 AM
  • Hi Muthu Nagarajan,

    I am marking this issue as "Answered". If you have any new questions or concerns about this issue, please feel free to let me know.

    Thank you and have a nice day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 9, 2011 3:43 AM
  • Unfortunately setting e.Handled also prevents the contxt menu from showing. The desired effect is usually to have the context menu opened and applied to ALL of the selected rows!

    Microsoft ALM Ranger

    Sunday, October 7, 2012 11:56 AM