Enabling LINQ for BindingListView

前端 未结 2 1424
清歌不尽
清歌不尽 2020-12-29 16:25

Andrew Davies created an excellent little class on sourceforge called BindingListView which essentially allows you to bind a collection to a Data

2条回答
  •  感情败类
    2020-12-29 16:38

    Ok this is what I got: Here is my extension method :

    public static class BindingViewListExtensions
    {
      public static void Where(this BindingListView list, Func function)
      {
        // I am not sure I like this, but we know it is a List
        var lists = list.DataSource as List;
    
        foreach (var item in lists.Where(function))
        {
            Console.WriteLine("I got item {0}", item);
        }
      }
    

    }

    And then I used it like :

        List source = new List() { "One", "Two", "Thre" };
    
        BindingListView binding = new BindingListView(source);
    
        binding.Where(xx => xx == "One");
    

    I guess where in the extension method could return the found item.

提交回复
热议问题