Reputation: 371
I want my datagrid to only allow one row to selected.
I guess I can do this by adding code to the datagridviews selectionChanged-event, but is there a better solution?
I would prefer to just have a property to set, i.e. : mydatagridview.maximumNrOfRowsSelected = 1
; or something similar.
Is there anything like this?
Upvotes: 37
Views: 41296
Reputation: 2413
Adriaan's answer didn't work for me, but Oscar's got me on the right track. Maybe something changed since Adriaan posted.
To get it working for me I changed SelectionMode
to FullRowSelect
.
Upvotes: 1
Reputation: 236
I guess it has changed. Right now the correct way for WPF is:
<DataGrid SelectionMode="Single"> ...
in your XAML file.
Upvotes: 15
Reputation: 166566
The DataGridView has a Property called MultiSelect ( default True ).
Set this to False.
Upvotes: 81