score:2

Accepted answer

I think it's better to get the filtered collection, instead for perform search after getting the collection. So I suggest you to use a Where clause like the following to get filtered items only:

string searchString ="A";

from row in repos.GetTable<Table_Names>() 
where row.Name.Contains(searchString)
select row.Name;

Instead for Contains you can also try StartsWith if you want to get the collection of strings that starts with the given search text.

score:0

If you don't want to filter in the database, you can use linq to objects to further filter the collection in memory:

var filtered = collectionName.Where(item => item.Contains("A")).ToArray();

score:0

You can use SqlMethods.Like in LINQ query. Check the code below

private void comboBox1_TextChanged(object sender, EventArgs e)
    {
        comboBox1.DataSource = getItems(comboBox1.Text);
        comboBox1.DisplayMember = "Name";
        comboBox1.ValueMember = "ID";
    }
    public static List<ComboboxItem> getItems(string text)
    {
        DataClasses1DataContext context = new DataClasses1DataContext();
        try
        {
            List<ComboboxItem> Ilist = new List<ComboboxItem>();
            var query =  from x in context.testComboBoxes where SqlMethods.Like(x.name, '%' + text +'%') select x;
            foreach (var q in query)
            {
                ComboboxItem item = new ComboboxItem();
                item.ID = q.id;
                item.Name = q.name;
                Ilist.Add(item);
            }
            return Ilist;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
    public class ComboboxItem
    {
        public object ID { get; set; }
        public string Name { get; set; }
    }

Related Articles