Search code examples
c#winformslistviewitem

How to Display a form with the same name selected in the subitem of listviewitem


I want to open a form with the same name selected in the subitem of listviewitem

example - if i select Buy in the list view check this link

https://i.sstatic.net/AKMKF.jpg

I want to open a form with the same name called Buy check this link

https://i.sstatic.net/BMX1K.jpg

Thanks In Advance.


Solution

  • you can find list views selected item by : SelectedItems property, Also you can get related text from subitems of listview, at last you can create a form and name it's text as selected text, sth like bellow code, just should add some checking for null selected items list.

    var txt = listView1.SelectedItems[0].SubItems[1].Text;
    var form = new Form();
    form.Text = txt;
    form.ShowDialog();