How to do lookup?

Stimulsoft Reports.NET discussion
Post Reply
Peter Illes
Posts: 18
Joined: Tue Jun 26, 2007 8:04 am
Location: Hungary

How to do lookup?

Post by Peter Illes »

Hi,

I'd like to have a Text in the report to be filled out by the name of an "enum" if I know the ID (pseudo code: CURRENCY[VOUCHER.CURRENCY_ID].ABBREVIATION, where CURRENCY_ID is the primary key of CURRENCY).

How is this best done?

Thanks,
Peter
Peter Illes
Posts: 18
Joined: Tue Jun 26, 2007 8:04 am
Location: Hungary

How to do lookup?

Post by Peter Illes »

What I figured out is this: {CURRENCY.DataTable.Rows.Find(VOUCHER.CURRENCY_ID)["ABBREVIATION"]}

Is there anything better?
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How to do lookup?

Post by Edward »

Peter wrote:I'd like to have a Text in the report to be filled out by the name of an "enum" if I know the ID (pseudo code: CURRENCY[VOUCHER.CURRENCY_ID].ABBREVIATION, where CURRENCY_ID is the primary key of CURRENCY).
So we have two DataSources in report. Here they are:
CURRENCY with CURRENCY_ID filed as a primary key
and
VOUCHER with CURRENCY_ID field as a primary key

The simplest way to connect these two tables is to create a relation between them.
Parent: CURRENCY (as I understand it is a dictionary for currencies)
Child: VOUCHER (here you need to show the ABBREVIATION for each Currency)

When the DataSource is connected with a DataBand (in our case it is VOUCHER DataSource) then the scrolling is done from record to record automatically. But you also can find a record you need manually via
DataSource.Next() or
DataSource.Prior() methods.

The relation for VOUCHER will point to record you need from the Detail (Currency.ABBREVIATION) datasource automatically.

In report you refer such fields via relation directly:

{CURRENCY.VOUCHER_Relation_Name.ABBREVIATION}

Thank you.
Peter Illes
Posts: 18
Joined: Tue Jun 26, 2007 8:04 am
Location: Hungary

How to do lookup?

Post by Peter Illes »

Edward,

Thanks for the reply. I ended up using the following function:

Code: Select all

		public System.String Lookup(string key, Stimulsoft.Report.Dictionary.StiDataTableSource ds, string valueCol)
		{
			try
			{
				return ds.DataTable.Rows.Find(key)[valueCol].ToString();
			}
			catch
			{
				return "";
			}
		}
This way the code is quite clean and self-explanatory. One may define additional overloaded versions, if their key is not string (e.g. decimal, etc.), or use .ToString() accordingly.

Cheers,
Peter
Edward
Posts: 2913
Joined: Fri Jun 09, 2006 4:02 am

How to do lookup?

Post by Edward »

It is really smart solution for your task.

Thank you.
Post Reply