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.
Unfortunately, activation email could not send to your email. Please try again.

Relate BusinessObjects in GridGroupingControl

Thread ID:

Created:

Updated:

Platform:

Replies:

104520 Jul 26,2012 06:37 AM Aug 10,2012 05:47 AM Windows Forms 5
loading
Tags: GridControl
Mr. Sascha Wald
Asked On July 26, 2012 06:37 AM

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:

For Each computerItemProperty In computerPropertyType.GetProperties()

singlecol = New GridColumnDescriptor(computerItemProperty.Name, computerItemProperty.Name, computerItemProperty.Name)

singlecol.AllowFilter = True

singlecol.HeaderText = ResourceHelper.ResourceString(AssetElementType.Computer, singlecol.Name)

If singlecol.Name.ToUpper().EndsWith("OWNERID") Then ownerIDColumnName = singlecol.Name

allCol.Add(singlecol)

End If

Next

m_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

Private Sub InitializeUsertable()

If m_UserTable Is Nothing Then

m_UserTable = New DataTable()

m_UserTable.Columns.Add(m_userID, GetType(Integer))

m_UserTable.Columns.Add(m_userName, GetType(String))

End If

End Sub


Private
Sub FillUserTable()

m_UserTable.Rows.Clear()

m_UserCollection = m_Session.FacadeFactory.UserFacade.ReadList(String.Empty)

For Each singleuser In m_UserCollection

m_UserTable.Rows.Add(singleuser.Id, singleuser.Lastname + ", " + singleuser.Firstname)

Next

End Sub

Syncfusion Version: 10.2.0.75

 


Kalaiarasan B [Syncfusion]
Replied On August 2, 2012 07:25 AM

Hi Sacha,

Please try the attached sample and let me know if this helps.

http://www.syncfusion.com/downloads/Support/DirectTrac/97200/ForeignKeyLookup-1271848443.zip

Regards,
Kalai

Mr. Sascha Wald
Replied On August 8, 2012 11:02 AM

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).

For Each computerItemProperty In computerPropertyType.GetProperties()

singlecol = New GridColumnDescriptor(computerItemProperty.Name, computerItemProperty.Name, computerItemProperty.Name)
singlecol.AllowFilter =
True
singlecol.HeaderText = ResourceHelper.ResourceString(AssetElementType.Computer, singlecol.Name)
If singlecol.Name.ToUpper().EndsWith("OWNERID") Then m_OwnerIDColumnName = singlecol.Name 'My relationColumnName
allCol.Add(singlecol)
'Workaround to get localized header text:
HeaderTextDic.Add(singlecol.Name.ToUpper(), singlecol.HeaderText)
Next
''Setup Dynamic Filter: Don't work anymore (no error, but doesnt work)
m_Filter.WireGrid(m_ComputerGridGroupingControl)

...'Doing stuff to relate OwnerId with usertable --> works...

' 

'Setup HeaderText (loclized)
Dim singleGridCol As GridColumnDescriptor
For Each singleGridCol In m_ComputerGridGroupingControl.TableDescriptor.Columns
If HeaderTextDic.ContainsKey(singleGridCol.Name.ToUpper()) Then
singleGridCol.HeaderText = HeaderTextDic(singleGridCol.Name.ToUpper())
End If
Next

'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)

 


Kalaiarasan B [Syncfusion]
Replied On August 9, 2012 08:19 AM

Hi Sascha,

Please refer the below sample which features both the dynamicfilter and relations in the GridGroupingControl.


Please let me know if this doesn't resolve what you are looking for

Regards,
Kalai

Mr. Sascha Wald
Replied On August 10, 2012 05:18 AM

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?


Kalaiarasan B [Syncfusion]
Replied On August 10, 2012 05:47 AM

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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;