I am using a collection myComputers as datasource for a GridGroupingControl.
The object myComputers implements ITypedList and Inherits the singleobjects as a list
Inherits List(of IMyComputer)
The fields to be populated are fetched by the initialization-method and reflects the properties of the collection:
singlecol =
New GridColumnDescriptor(computerItemProperty.Name, computerItemProperty.Name, computerItemProperty.Name)singlecol.AllowFilter =
Truesinglecol.HeaderText =
ResourceHelper.ResourceString(AssetElementType.Computer, singlecol.Name) If singlecol.Name.ToUpper().EndsWith("OWNERID") Then ownerIDColumnName = singlecol.NameallCol.Add(singlecol)
End If Nextm_ComputerGridGroupingControl.TableDescriptor.Columns = allCol
Now I tried to add a relation between an object of the MyComputerCollection and a table "Users"
GridForeignKeyHelper.SetupForeignTableLookUp(m_ComputerGridGroupingControl, ownerIDColumnName, m_UserTable, m_userID, m_userName)m_UserTable is initialized and filled up before the init of the grid (see details info);
m_userID and m_userName are the names of then columns in the m_UserTable.
ownerIDColumnName ist the object name of the column I want to assign the users values and is assigned during iterating through the Properties of the collection and has the Id in it.
What I expect is that in the column (ownerIDColumnName) of the grid the value of the usertable (the name of the user) appears. Instead, it allways shows the id of the user (the value stored in the MyComputers-Collection).
Can you help me?
Thanks,
Sascha
_______________________
detail info usertable:
''' Initialize m_UserTable
m_UserTable =
New DataTable()m_UserTable.Columns.Add(m_userID,
GetType(Integer))m_UserTable.Columns.Add(m_userName,
GetType(String)) End If End Subm_UserTable.Rows.Clear()
m_UserCollection = m_Session.FacadeFactory.UserFacade.ReadList(
String.Empty) For Each singleuser In m_UserCollectionm_UserTable.Rows.Add(singleuser.Id, singleuser.Lastname +
", " + singleuser.Firstname) Next End SubSyncfusion Version: 10.2.0.75
Thank you for this example. It worked when I use it 1:1 in my application.
But what I am also doing, and this does not work with your solution, is:
- I get the columns header text from a resource depending on the columns name
- I remove not needed columns
- I assign the automatic filter object (GridDynamicFilter)
When doing this, the relation is not working (it shows Ids instead of name); when using your solution, the relation works but I get the default header names (ok, I can make a workaround to get it to work), but the filter doesn't work anymore (the filter row shows no icon and you cannot click into it).
singlecol =
New GridColumnDescriptor(computerItemProperty.Name, computerItemProperty.Name, computerItemProperty.Name)...'Doing stuff to relate OwnerId with usertable --> works...
'
'Setup HeaderText (loclized)'This does not work when wokring with relations:
''Spalten dem Grid zuweisen
'm_ComputerGridGroupingControl.TableDescriptor.Columns.Clear()
'm_ComputerGridGroupingControl.TableDescriptor.Columns = allCol
''remove invisible cols
'If invisibleCol.Count > 0 Then
' For Each invCol As GridColumnDescriptor In invisibleCol
' m_ComputerGridGroupingControl.TableDescriptor.VisibleColumns.Remove(invCol.Name)
' Next
'End If
______________
So my main problem is now: how to get the filter work? (For other problems I have workarounds)
Ok, this worked, thank you. I added the iteration to set allowFilter = true to each column, that did the job.
But I have another strange behavior in this context.
I store the layout of the grid (selected columns etc) in an XML file using
LayoutHelper.SaveGridLayout(...)
Now, when loading the Layout, the content for this related column (user) does not appear.
In XML it seems to be fine, the relation and the column User is tagged as GridVisibleColumnDescriptor:
<GridRelationDescriptor><MappingName /><RelationKind>ForeignKeyReference</RelationKind><RelationKeys><RelationKeyDescriptor><ChildKeyFieldName>userid</ChildKeyFieldName><ParentKeyFieldName>OwnerId</ParentKeyFieldName></RelationKeyDescriptor></RelationKeys><Name>OwnerColDisplay</Name><ChildTableName>UserTable</ChildTableName><GridChildTableDescriptor><SortedColumns><SortColumnDescriptor><Name>username</Name><SortDirection>Ascending</SortDirection></SortColumnDescriptor></SortedColumns><AllowNew>false</AllowNew><AllowEdit>false</AllowEdit><VisibleColumns><GridVisibleColumnDescriptor><Name>username</Name></GridVisibleColumnDescriptor></VisibleColumns></GridChildTableDescriptor></GridRelationDescriptor></Relations>
and the mapping seems to be ok:
<GridColumnDescriptor><HeaderText>User</HeaderText><Width>154</Width><MappingName>OwnerColDisplay_username</MappingName><AllowFilter>true</AllowFilter></GridColumnDescriptor>
When I disable LayoutHelper.LoadGridLayout(...), the usercol works fine.
Am I missing an update-action?
Hi
Sascha,
Thank you for the update.
Please make use of the following codes to serialize the Gird than using LayoutHelper. You can even save the Grid with its look and feel too.
XmlTextWriter xw = new XmlTextWriter("GridSchema.xml", System.Text.Encoding.UTF8);
XmlTextWriter xwApp = new XmlTextWriter("GridLooknFeel.xml",
System.Text.Encoding.UTF8);
xw.Formatting
= System.Xml.Formatting.Indented;
this.gridGroupingControl1.WriteXmlSchema(xw);
this.gridGroupingControl1.WriteXmlLookAndFeel(xwApp);
xw.Close();
xwApp.Close();
XmlReader xr = new XmlTextReader("GridSchema.xml");
XmlReader xrApp = new XmlTextReader("GridLooknFeel.xml");
this.gridGroupingControl1.ApplyXmlSchema(xr);
this.gridGroupingControl1.ApplyXmlLookAndFeel(xrApp);
xr.Close();
xrApp.Close();
Sample : http://www.syncfusion.com/downloads/Support/DirectTrac/96954/ForeignKeyLookup_852567420.zip
Please let us know if you have any concerns
Regards,
Kalai