select item from listview and cast to my custom object

后端 未结 3 1631
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-22 20:13

I\'m trying to select object from listview and cast to my custom object like this

MyObject foo = (MyObject)MyListView.SelectedItems[0];

but thi

3条回答
  •  无人及你
    2021-01-22 21:10

    I think you need to create your object differently, not casting in this way.

    If you retrieve the text in the item, then create your object using that text.

    string txt   = MyListView.SelectedItems[0].Text;
    MyObject foo = new MyObject(txt);
    

    Then use your object in the usual way. It is difficult to tell any more about what you need without more details.

提交回复
热议问题