Sebastian Larsson
Sebastian Larsson

Reputation: 371

Make it possible to ONLY select one row in datagrid?

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

Answers (3)

tmwoods
tmwoods

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

Oscar Fonseca
Oscar Fonseca

Reputation: 236

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

<DataGrid SelectionMode="Single"> ...

in your XAML file.

Upvotes: 15

Adriaan Stander
Adriaan Stander

Reputation: 166566

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

Set this to False.

Upvotes: 81

Related Questions