Cast ListView Items to List?

后端 未结 4 821
[愿得一人]
[愿得一人] 2021-02-13 11:02

How can I cast ListView.Items to a List?

This is what I tried:

List list = lvFiles.Items.Cast

        
4条回答
  •  感动是毒
    2021-02-13 11:23

    Try this using the Select method:

    for list text:

    List listText = lvFiles.Items.Select(item => item.Text).ToList();
    

    for list values:

    List listValues = lvFiles.Items.Select(item => item.Value).ToList();
    

    Or maybe, for both:

    Dictionary files = lvFiles.Items.ToDictionary(key => key.Value, item => item.Text);
    

提交回复
热议问题