No, unfortunately, this is not possible. Although it is likely that using a particular data source will make this search quite simple, making it a more general way (since BindingSource ) will be slightly less transparent. First, the syntax will be less obvious. Here is a somewhat far-fetched solution:
public class Key { public string PropertyName {get; set;} public object Value {get; set;} } public static int Find(this BindingSource source, params Key[] keys) { PropertyDescriptor[] properties = new PropertyDescriptor[keys.Length]; ITypedList typedList = source as ITypedList; if(source.Count <= 0) return -1; PropertyDescriptorCollection props; if(typedList != null)
You can call it like this:
BindingSource source = // your BindingSource, obviously int index = source.Find( new Key { PropertyName = "PetType", Value = "Dog" }, new Key { PropertyName = "Gender", Value = "M" });
Keep in mind that in order for this to be useful, you really need a more reasonable comparison algorithm, but I will leave this as an exercise for the reader. Verifying the implementation of IComparable would be a good start. However, the concept should be implemented regardless of the specific point of implementation.
Note that this will not use any of the possible performance optimizations that can be implemented by the underlying data source, while a single Find column will be.
source share