how display selected row listview textbox?
this how int datagridview:
private void datagridview1_cellclick(object sender, datagridviewcelleventargs e) { datagridview1.rows[e.rowindex].readonly = true; if (datagridview1.selectedrows.count != 0) { datagridviewrow row = this.datagridview1.selectedrows[0]; empidtextbox.text = row.cells["empid"].value.tostring(); empnametextbox.text = row.cells["empname"].value.tostring(); } }
i tried this:
private void listview1_selectedindexchanged(object sender, eventargs e) { listviewitem item = listview1.selecteditems[0]; if (item != null) { empidtextbox.text = item.subitems[0].text; empnametextbox.text = item.subitems[1].text; } }
you may want check if there selecteditem first. when selection changed, listview
unselect old item select new item, hence triggering listview1_selectedindexchanged
twice. other that, code should work:
private void listview1_selectedindexchanged(object sender, eventargs e) { if (listview1.selecteditems.count > 0) { listviewitem item = listview1.selecteditems[0]; empidtextbox.text = item.subitems[0].text; empnametextbox.text = item.subitems[1].text; } else { empidtextbox.text = string.empty; empnametextbox.text = string.empty; } }
Comments
Post a Comment