Method: Sources.SelectFirst( … )
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 | Name of the Data Source to search in. |
string | Expression used to filter rows, similar to SQL. |
string | Optional value specifying the column to sort and direction. |
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"];