We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

GridGroupingControl: Problem when using foreign key reference functionality

I want to change foreign key reference in my table by values from referenced table and display referenced table.

My sample is taken from Syncfusion Grid.Grouping samples. It tries to do functionality, implemented above, but problem is that each foreign key column is multipled by referenced table column count (every referenced table separate column is displayed in each of them). I need to have some value from the referenced table displayed instead of foreign key value.

Here is the code sample I used:

DataTable dataTable = new DataTable();
dataTable.TableName = "TestTable";
dataTable.Columns.Add("Key", typeof(string));
dataTable.Columns.Add("Name", typeof(string));
DataColumn column=dataTable.Columns.Add("Name2", typeof(string));


//dataTable.Columns[0].
// and then add a few rows:
for ( int i=1; i < 10000; i++ )
{
DataRow newRow=dataTable.NewRow();
dataTable.Rows.Add(newRow);
newRow[0] = i; //Key
newRow[1] = "Hipopotamus"+i.ToString();
newRow[2] = "Monkey" + i.ToString();
}
_dataSet.Tables.Add(dataTable);

GridTable gridTable = _gridGrouping.GetTable("ENDOTRACHIAL_ADAPTER");
GridTableDescriptor tableDescriptor = gridTable.TableDescriptor;
_gridGrouping.Engine.SourceListSet.Add("TestTable",dataTable);

GridRelationDescriptor stringFieldRd = new GridRelationDescriptor();
stringFieldRd.Name = "DisplayField";
stringFieldRd.RelationKind = RelationKind.ForeignKeyReference;
stringFieldRd.ChildTableName = "TestTable"; // SourceListSet name for lookup
stringFieldRd.RelationKeys.Add("DIAMETER_id", "Key");
stringFieldRd.ChildTableDescriptor.Appearance.AlternateRecordFieldCell.BackColor = Color.Beige;
//stringFieldRd.ChildTableDescriptor.VisibleColumns.Add("Key");
//stringFieldRd.ChildTableDescriptor.VisibleColumns.Add("Name");
//stringFieldRd.ChildTableDescriptor.VisibleColumns.Add("Name2");
//stringFieldRd.ChildTableDescriptor.SortedColumns.Add("Name");
stringFieldRd.ChildTableDescriptor.AllowEdit = false;
stringFieldRd.ChildTableDescriptor.AllowNew = false; // Make pencil icon disappear, users can''t modify states.
tableDescriptor.Relations.Add(stringFieldRd);

3 Replies

AD Administrator Syncfusion Team September 2, 2006 11:14 PM UTC

I do not understand what you are describing as not working for you. Here is a sample based on the code you showed. What do you want to see different in the sample?

http://www.syncfusion.com/Support/user/uploads/WrapTextGGC_3fdcc6f1.zip


VI Vitaliy September 4, 2006 10:11 AM UTC


In grid it is necessary to display only one field from table "TestTable" ("Name" or "Name2")...


AD Administrator Syncfusion Team September 5, 2006 12:32 PM UTC

No. The sample in the previous post displays both the Name and Name2 columns.

By Default, all columns in the lookup table (except the actual mapped indexed column) appear in the main grid. You have to explicilty hide the ones you do not want to see.

Loader.
Live Chat Icon For mobile
Up arrow icon