mvvm - Bind to selected items in WPF DataGrid -
i want know selected items in datagrid (insert them collection in viewmodel).
when bind selected item changed when click on row (1 row), when press ctrl + clicking remains first item, why happening , possible link selected items?
here datagrid:
<datagrid selectedindex="{binding selectedxindex}" datacontext="{binding xviewmodel}" selecteditem="{binding currentx}" itemssource="{binding listx, mode=twoway}" autogeneratecolumns="false" > <datagrid.columns> ... </datagrid.columns> </datagrid>
in xviewmodel have:
selectedxindex
(int) selected index
currentx
(object of class x) current selection
listx
- list of class x
the first suggestions made did not work. leave them historical reasons.
i think problem want kind of unusual - or error prone. set bind selecteditem (one item) while want able select multiple.
i set no binding @ in xaml (except itemssource of course) , track selection changes selectionchanged event in end code. link similar problem supporting method found here
hope find improve solution
old suggestions:
this should solve issue seem treating single mode selection datagrid nto explicitely define such:
<datagrid selectionmode="single"
if want selection mode multiple should not bind selectedindex
i wonder why have both selectedindex binding , selecteditem binding. in case 1 should needed.
keep selecteditem binding set selectionmode extended , seek again
wpf mvvm datagrid selecteditem
No comments:
Post a Comment