Use if you need flexible criteria for lookup of values from other Table Data Sources.
Returns the first row from the specified data source that matches the filter-expression after any optional specified sorting of the rows.
Note: This method is very flexible in what criteria you can apply when searching in other data sources. However, it can be very slow if a data source is large. For very fast search performance use the Sources.Find(…) or Sources.FindValue(…) methods instead.
Syntax
DataRow Sources.SelectFirst( string sourceName, string filterExpression, string sort = "" )Method Parameters
|
string sourceName |
Name of the Data Source to search in. The Data Source must be of the Table type which is the default returned data source by all Select Commands. |
|
string filterExpression |
Expression used to filter rows, similar to SQL. Example: "Cylinder=8 AND Price > AVG(Price)" For more specific documentation on the filter-syntax, check the Microsoft documentation for the DataView RowFilter Syntax [C#]. |
|
string sort |
Optional value specifying the column to sort and direction. Example: "Price ASC" |
Example
Below example shows how to lookup values in a lookup table in order to convert some input values, e.g. if the input source has values like R, G and B, but you want it to be Red, Green and Blue instead.
In below example a data source named Color contains a translation table with 2 columns named ColorCode and ColorName. Values are looked up via the ColorCode column to get the ColorName that is wanted.
if( !HasValue ) return;
var lookup = Sources.SelectFirst( "Colors", "ColorCode='" + Value + "'" );
if( lookup != null )
Value = lookup["ColorName"];
Comments
0 comments
Please sign in to leave a comment.