c# - How to get selected item in ListView to TextBox? -
c# - How to get selected item in ListView to TextBox? -
how selected item in listview textbox?
private void txtautosgn_textchanged(object sender, textchangedeventargs e) { if (txtautosgn.text.length > 1) { var names = (from autonames in lstdetails autonames.name.contains(txtautosgn.text.trim()) select autonames.name).tolist(); if (names.count > 1) { lstnames.items.clear(); lstnames.visibility = visibility.visible; foreach (string name in names) { lstnames.items.add(name); } lstnames.selectedindex = 0; } else { lstnames.visibility = visibility.collapsed; } } }
in method, instead of adding item in listview
, set itemssource
of like:
var names = (from autonames in lstdetails autonames.name.contains(txtautosgn.text.trim()) select autonames.name).tolist(); if (names.count > 1) { lstnames.items.clear(); lstnames.visibility = visibility.visible; lstnames.itemssource = names; lstnames.selectedindex = 0; } else { lstnames.visibility = visibility.collapsed; }
and in xaml can bind selecteditem
of listview
textbox
as
<grid> <textbox text="{binding selecteditem, elementname=lstnames}"></textbox> <listview x:name="lstnames"></listview> </grid>
c# wpf listview
Comments
Post a Comment