A quick question about DataGrid

S

Sowen Cheung

Hello

How can I bind a column's value to another table?

All tables are in the dataset already, I just have two tables and I bind
table1 to the datagrid

eg)

table1
column....,level_id, level2_id,...

level_id is a FK to table2,

I want to show the level_name instead of level_id.

How can I show table2's level_name according to each record's level_id?

Thank you very much!

--
Best Regards!
Sowen Zhang
http://com.angGoGo.com
http://www.angGoGo.com
http://biz.angGoGo.com
 
B

Bart Mermuys

Hi,

Sowen Cheung said:
Hello

How can I bind a column's value to another table?

All tables are in the dataset already, I just have two tables and I bind
table1 to the datagrid

eg)

table1
column....,level_id, level2_id,...

level_id is a FK to table2,

I want to show the level_name instead of level_id.

How can I show table2's level_name according to each record's level_id?

You can add a relation between the two table's and then use expression
columns to resolve the foreign key. It's important to remember that the
lookup table (table2 here) is the parent table.

Suppose you have a DataSet ds with two tables:

ds.Relations.Add( "rel1",
ds.Tables["table2"].Columns["level_id"],
ds.Tables["table1"].Columns["level_id"] );

// add resolved foreign key
ds.Tables["table1"].Columns.Add("level_name", typeof(string),
"Parent(rel1).level_name");

HTH,
Greetings
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top