score:2
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; }
}
Source: stackoverflow.com
Related Articles
- Linq into the array then find values in the array and list to combobox
- LINQ datarow string to array and then into to string list
- Find the Second Max in a list of values using linq c#
- Group by key and send values into list using LINQ
- Using Linq find first object in list sorting by property A, then property B
- Find list of values for item using Linq
- Convert List of array into the list of KeyValuePairs using LINQ
- LINQ - GroupBy a key of paired object, then separate the grouped object into list of 2 objects?
- LINQ join, then group by, into strongly-typed List of classes
- Using Linq to find if a list contains an incremental sequence of at least 5 values
- Linq code to get the index of an object in an array from an object within a list
- C# LINQ Find List Inside Another List, Better way to code this than a foreach loop
- Search an Object list for duplicate keys, and place string values into a string array
- LINQ query to find objects in list with equal values for one of their properties
- Select values from multiple dictionaries into list of objects with LINQ
- Saving values into List in a class by using LINQ
- Using Linq to find only records that have all matching values in list of flags?
- How to iterate in a list to find names and values with linq
- Split array or list into segments using LINQ
- How to get a list of filtered values in Dictionary into a List using LINQ or Lambda?
- List or Array of String Contain specific word in Html Source Code
- C# LINQ statement with joins, group by and having then mapped into list object
- c# Aggregate an enumerable containing a list<string> into one union list then get distinct values
- Linq split list into sublists then iterate
- c# Linq or code to extract groups from a single list of source data
- LINQ query stores values in KeyValuePair<string, string> list but then cannot store them all with addrange
- linq : find values in list exist in another list or not?
- LINQ Query with multiple conditions and setting values into a list
- Using LINQ to find duplicate min values in array C#
- C# LINQ find duplicates in List
- Group by multiple Values in Linq
- "The parameter was not bound in the specified LINQ to Entities query expression." Specification Pattern And
- Order by not-selected column
- Reading Element Value from xml message with multiple namespaces
- linq query to split nested lists into multiple tables
- Only parameterless constructors and initializers are supported in LINQ to Entities
- Compare two lists via two property in addition to having list of unique values from third property creating new lists
- Why Enumerable doesn't inherits from IEnumerable<T>
- Dynamic Linq GroupBy Select not working properly
- Editing XML Output With LINQ
- Distinct in LINQ to SQL is not working as expected(at all)
- LinqToCRM does not cast properly
- Dictionary Union to dictionary?
- LINQ and various joining sample
- Linq to XSD processing
- Update collection from DbSet object via Linq
- counting Movie by grouping alphabetically using linq
- Combine expressions for Where statement
- linq Custom ordering without taking all records
- Converting array of objects to XML in C#