locked
Multiple selection lost when user right clicks on the row header in a DataGrid RRS feed

  • Question

  • After selecting multiple rows, if I right click on the row, the multiple selection remains. But when I right click on the header, only that particular row is selected.

    What should I do to keep the selected items as it is? 

    Friday, June 5, 2015 9:42 AM

Answers

  • I cannot reproduce your issue. If I set the SelectionMode property to Extended and the SelectionUnit property to FullRow and select several rows by clicking on them and holding down the CTRL key simultaneously and then right-click on the header no rows are deselected.

    So make sure that you don't have some custom code that cases the selection to get cleared.

    Obviously you need to provide a reproducable sample for further help but please add a new DataGrid with no custom code to your window (or create a new solution to test it), populate it with some sample data and try to reproduce the issue yourself first. You will probably fail just like I did and then you know there is something in your custom code that causes the selection to be cleared.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Friday, June 5, 2015 10:21 AM

All replies

  • The way multiple selection is supposed to work is you hold ctrl down and click another row if you want to select several.

    Not right click.

    If you use ctrl+click then it works whether you click header or row.

    On win 8.1 if I right click a second row in a datagrid it selects just that row.

    I suggest you go with ctrl + click as designed.

    If you prefer to stick with what you have then you could hide the row headers using

    <DataGrid x:Name="dg"
                       HeadersVisibility="Column"


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Friday, June 5, 2015 10:01 AM
  • I cannot reproduce your issue. If I set the SelectionMode property to Extended and the SelectionUnit property to FullRow and select several rows by clicking on them and holding down the CTRL key simultaneously and then right-click on the header no rows are deselected.

    So make sure that you don't have some custom code that cases the selection to get cleared.

    Obviously you need to provide a reproducable sample for further help but please add a new DataGrid with no custom code to your window (or create a new solution to test it), populate it with some sample data and try to reproduce the issue yourself first. You will probably fail just like I did and then you know there is something in your custom code that causes the selection to be cleared.

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Friday, June 5, 2015 10:21 AM