37

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?

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
Sebastian Larsson
  • 371
  • 1
  • 3
  • 3

3 Answers3

77

The DataGridView has a Property called MultiSelect ( default True ).

Set this to False.

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284
14

I guess it has changed. Right now the correct way for WPF is:

<DataGrid SelectionMode="Single"> ...

in your XAML file.

Tassisto
  • 9,877
  • 28
  • 100
  • 157
Oscar Fonseca
  • 226
  • 2
  • 6
1

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.

tmwoods
  • 2,353
  • 7
  • 28
  • 55
  • It's just that Adriaans answer is suited for WinForms and Oscars for WPF they are 2 seperate UI frameworks. (although the question specifically requested an answer for WinForms...) – Robin B Sep 26 '19 at 09:23