Disable Row Selection?

Nov 9, 2008 at 10:51 PM
Edited Nov 9, 2008 at 11:15 PM

For some reason the enum SelectionMode does not contain "Disabled" or "None" etc.

Is there a recommended way to disable row selection?

I've created this style which nearly does the job, but for some reason when you select a row the padding appears to reduce from its original, creating a strange effect. I can't override this behavior for some reason.

            <Style x:Key="dataGridRowStyle" TargetType="{x:Type Controls:DataGridCell}">
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="Background" Value="Transparent"></Setter>
                        <Setter Property="Foreground" Value="Black"></Setter>
                        <Setter Property="BorderThickness" Value="0"></Setter>




Nov 10, 2008 at 12:28 PM
If you want to disable row selection you can set the SelectionUnit to Cell.  Do you want to disable all selection?  If so, you will have to override DataGridCell's Style.
Nov 10, 2008 at 6:38 PM
Correct, I want the entire row (cells inclusive!) to be disabled from selection.

If you read my orignial post again I have already tried overriding DataGridCell's Style.
Nov 10, 2008 at 7:34 PM
I haven't fully investigated the reason why the padding is producing a strange effect but you can always override the default DataGridCell.Style:



Style x:Key="defaultCellStyle" TargetType="{x:Type dg:DataGridCell}">
    <Setter Property="OverridesDefaultStyle" Value="True" />


Nov 10, 2008 at 7:53 PM

Hi warriors89,

Could you explain your scenario a little further?  The reason I ask is because we had considered at one point adding a SelectionMode=None feature, but we had trouble thinking of a compelling customer scenario where selection would be disabled.  In most scenarios, having a read-only grid was sufficient and even with a read-only grid, selection was desired so that users could copy or highlight data while reading.  This is a feature which we could consider adding in V2, so I'd like to understand why your application requires that the user can't select anything.



Nov 10, 2008 at 9:36 PM
OK great, thanks for your help :)
Nov 10, 2008 at 9:45 PM

Hi Samantha, we have a specific requirement where we're displaying read-only tabular data in a "List View" arrangement, but we want to toggle precisely when to display horizontal grid lines, while vertical grid lines are always displayed.

We could achieve this by using the Grid control, but it's much easier with the DataGrid as it has the grid lines toggling feature baked in.

Having the ability for the user to select a row just doesn't make sense in this instance.

Kind regards,

Jamie aka Warriors89.

Dec 4, 2008 at 3:35 PM
Hi Samantha.

I also have a scenario for you. I want to disable the selection of a row and entering the edit-mode when I just press the row. But instead I want a context-menu, giving me the choice of: Add new row, Edit row, Delete row. And when I choose the Edit row I want that row to go into edit mode and highlight as selected row. Right now when a right-click a row for the context-menu that row gets selected, and that's not very nice.

I also have readonly list I want to show, could do that with ListView but lot's of goodies built in to the DataGrid so why not use that instead. Right now I change the background color of the row when hovering over it, so for me there is no need to mark a readonly row as selected. When I click the row an detailview window would be opened.


Magnus Gladh

Dec 4, 2008 at 6:13 PM
Thanks for providing those scenarios, Magnus.  We will certainly take this feedback into account when prioritizing features for V2.  Thanks!
Dec 6, 2008 at 1:21 PM
I would also like to see this feature.  I have textblocks within a cell that I want to drag and drop to other cells, however the cell keeps on getting selected and looks unsightly!!
Dec 8, 2008 at 7:01 PM
Thank you for providing this scenario.  I've recorded all of these suggestions and sample scenarios in our database and we will take this feedback into account when prioritizing features for V2.  Thanks!