using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows.Forms;
using System.Collections;       // For System.Collections.IEnumerable.

namespace SelectListItemByText
{
    public static class ListExtensions
    {
        // Find an item containing the target string.
        private static object FindItemContaining(IEnumerable items, string target)
        {
            foreach (object item in items)
                if (item.ToString().Contains(target)) return item;
            return null;
        }

        public static object FindItemContaining(this ComboBox cbo, string target)
        {
            return FindItemContaining(cbo.Items, target);
        }
        public static object FindItemContaining(this ListBox lst, string target)
        {
            return FindItemContaining(lst.Items, target);
        }
    }
}
