Extract content from a Listview column c#/wpf -
i'm populating listview sql database. listview has 3 columns defined xaml.
<listview x:name="lstas7" grid.row="1"> <listview.view> <gridview> <gridviewcolumn x:name="as7nom" header="{dynamicresource as7_nom}" width="350" displaymemberbinding="{binding as7_nom}"/> <gridviewcolumn x:name="as7lib" header="{dynamicresource as7_lib}" width="350" displaymemberbinding="{binding as7_lib}"/> <gridviewcolumn x:name="as7prix" header="{dynamicresource as7_prix}" width="80" displaymemberbinding="{binding as7_prix}"/> </gridview> </listview.view>
the code behind next one
foreach (datarow valeur in ds.tables["tb1"].rows) { lstas7.items.add(new { as7_nom = valeur["name"], as7_lib = valeur["text_short"], as7_prix = valeur["price"] }); }
for test add button retrieve content of selecteditems , show on screen messagebox. result.
{ as7_nom = "dvi_at_hs_unit_07242802", as7_lib = "set réservoirs de force ; ht de meuble: 676 - 800mm ; pour système aventos hs", as7_prix = 0 }
how can retrieve info 1 column, expl column "as7_nom"
since adding anonymous type objects items
collection of listview
use dynamic
keyword able retrive property values:
dynamic selecteditem = lstas7.selecteditem; if(selecteditem != null) messagebox.show(selecteditem.as7_nom.tostring());
the other option define class as7_nom, as7_lib , as7_prix properties , add intances of class listview
:
lstas7.items.add(new yourclass { as7_nom = valeur["name"].tostring(), as7_lib = valeur["text_short"].tostring(), as7_prix = valeur["price"].tostring() });
you cast selecteditem
property yourclass
, access properties in compile-time safe fashion:
yourclass selecteditem = lstas7.selecteditem yourclass; if(selecteditem != null) messagebox.show(selecteditem.as7_nom);
Comments
Post a Comment