c# - How to retrieve clicked list view row data and hide id column -
i retrieve data clicked listviews row. hide id column if it's possible. tried use commands click event , pass id field commandparammeter no success. searched other approaches nothing. information, need functionality show detailed information each clicked user other listview data easier view other users.
conclusion: need clicked row data , if possible, hide id column.
xaml code:
<listview x:name="lstusers" itemssource="{binding userlist,updatesourcetrigger=propertychanged}"> <listview.view> <gridview x:name="grdusers"> <gridviewcolumn header="hidden_id" displaymemberbinding="{binding id}"/> <gridviewcolumn header="name" displaymemberbinding="{binding name}"/> <gridviewcolumn header="surname" displaymemberbinding="{binding surname}"/> <gridviewcolumn header="age" displaymemberbinding="{binding age}"/> </gridview> </listview.view> </listview>
and inside viewmodel placed userlist.
kind of elegant approach gets clicked row data, thanks.
edit:
looked link @bradleydotnet gave , code looks this.
<listview x:name="lboxuser" itemssource="{binding userlist, updatesourcetrigger=propertychanged}" width="300" issynchronizedwithcurrentitem="true" visibility="visible" selectionmode="single" selectedvaluepath="id" selectionchanged="lboxuser_selectionchanged"> //this part hasn't changed </listview>
selectedvaluepath: attribute bind 1 of userlist object. in case 'id'.
selectionchanged: adding event handler execute on selection changed event , selected row data. know more elegant user mvvm pattern commands somehow didn't work me.
also display 'selectedvalue'.
<textblock text="{binding selectedvalue, elementname=lboxuser}"/>
edit2:
found easier way it.
<listview.selecteditem> <binding path="userproperty" updatesourcetrigger="propertychanged"/> </listview.selecteditem>
just added user class property inside viewmodel , thats all. gets selected user data. counts mvvm pattern.
you on way!
to rid of "id" column, pretty easy; delete it!
<listview x:name="lstusers" itemssource="{binding userlist,updatesourcetrigger=propertychanged}"> <listview.view> <gridview x:name="grdusers"> <gridviewcolumn header="name" displaymemberbinding="{binding name}"/> <gridviewcolumn header="surname" displaymemberbinding="{binding surname}"/> <gridviewcolumn header="age" displaymemberbinding="{binding age}"/> </gridview> </listview.view> </listview>
to information selected item, @ selectedvalue
(msdn) property of listview
hold bound object of selected item.
Comments
Post a Comment