Hello,
im using XamDataGrid hierachical through binding its DataSource to a hierachical DataSet, and provide they FieldLayout + RelationField for each FieldLayout/Table, dynamically. (I generate the grid all code-behind, no xaml. (Dynamic relations & columns.))
I dont want the relation headers "relation6" / "relation7" / ..
My problem is, i add multiple child-relations for a table - used by different rows. The grid now displays every relation for every row, even if its empty for this row. How should i provide the relations? Or Hide the relation-groups/headers? (hide relation field?)
GreetingsiA. Kits
Hi Joerg,
If I'm understanding this correctly, you just want to hide the relations that have no child records? This relations are appearing because a Field has been defined for that relation. I presume that you are using auto generated fields? You can hide these relations by using the following style:
<Style TargetType="{x:Type igWPF:ExpandableFieldRecordPresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Record.HasChildren}" Value="False"> <Setter Property="Height" Value="0"/> </DataTrigger> </Style.Triggers></Style>
Those relations that you see are called ExpandableFieldRecordPresenters. When there is children data you would normally be able to expand the relation and see the child data but if there are no children it does not hide the relation itself. You can do this with the above trigger. If there are no children in the ExpandableFielRecordPresenter then it will set the height to 0. We set the height to 0 because you can't actually set the Visibility to Collapsed. If you do, the record space will still be shown.
Hi Rob,
thanks for your fast response.
i dont want the ExpandableFieldRecordPresenters "relation6" / "relation7".. displayed at all. Also not for rows which has children.
I want it like you can see in the first hierachical level of my screenshot - the expansionindicator directly before the row, without any additional header "RelationName".
PS: I dont use auto generated fields. I generate them myself. I use KeyMatchingEnforced (and layout.Key = table.TableName).
- My childs are in seperate Tables, because they again can have own childs. - I generate a FieldLayout for each table including a field for its children (named of child-table).
My source data is one table referencing itself with ParentID -> ID. Its nested depth is dynamically. (It can be several levels)
Any hints on this?
Those ExpandableFieldRecordPresenters are there because your FieldLayout has more than one Field for the child data. When there is more than one Field it displays these presenters so the user can tell which is which. So there are two things that you can do in order to remove the ExpandableFieldRecordPresenters that you don't want to see. The first is to set the Visibility on the Field that represents that relation in your FieldLayout. If you set it to Collapsed then the child data will not be displayed. If you do this for every relation Field except the one you want then you will only see the single child set. You will still see the ExpandableFieldRecordPresenter for it though since the FieldLayout has more than one Field for child data.
This leads to the second option: remove the Field from the FieldLayout all together so there is only one relation Field. If there is only one relation Field then no ExpandableFieldRecordPresenters will be used and expanding the parent record will immediately show the single set of child records.
I have attached a basic sample that shows what I mean. If you run the sample as is, you will see two relation Fields: "ChildRelation1" and "ChildRelation2". Each has its own ExpandableFieldRecordPresenter. Now go to the code behind and into the CreateLayouts() method. You will see some commented out code with comments above them. The first one sets the Visibility on the Field that represents one of the child relationships. Comment this back in so it hides the field and then rerun the sample. You will see that when you expand the first record it still shows an ExpandableFieldRecordPresenter for "ChildRelation2". Go back to the code and then use the second commented out line. This removes the Field entirely. Rerun and you will see that no ExpandableFieldRecordPresenter is shown and it immediately shows the child data.
So basically you have to do the same thing in your application. If you aren't using those Fields, or you don't want to show their data then you should just remove the relation Field from your FieldLayout.
Actually a colleague pointed out that instead of removing the field in order to remove the ExpandableFieldRecordPresenter, you can set the ExpandableFieldRecordHeaderDisplayMode property in the XamDataGrid.FieldSettings. This property controls how the ExpandableFieldRecordPresenters are displayed.
unfortunately this doesnt seems to fit my need.
I dont want the expansion-indicator, i dont want the empty space of it - if i hide the header, i dont want the indent.
I got 1 table with 2 rows:
- Row A needs relation AR
- Childs AA got relation to AAR
- Row B need relation BR
- Childs BB got relation to BBR
Row A doesnt need to know, show or do anthing with relation BR.
Row B doesnt need to know, show or do anthing with relation AR.
I hope you can understand what i need.
PS: Should i create a FieldLayout for every row? Is that even possible?
I don't think I understand all that well. I think it mostly has to do with the fact that I'm not very good with DataTables :(. Would it be possible for you to send me a sample of what you have so far and I can try to make it work the way you need it? It would be nice to see how your DataTable and FieldLayouts are generated.
There is mention of those properties here but if I were to read that I wouldn't associate it with what you were trying to do. And honestly I wasn't aware of those properties until a colleague of mine pointed them out to me so he's the real hero here. :)
that's it!
Why was that so hard to archieve.. :/ Any hints where i could have searched for it in the documentation?
Thanks for your help.iA. Kits
Here is what I think you need to do. Just set these two properties and as long as your tables are configured such that each row only has 1 relation of it's own then it should display the type of grid you need.
dataGrid1.FieldSettings.ExpandableFieldRecordHeaderDisplayMode = ExpandableFieldRecordHeaderDisplayMode.NeverDisplayHeader;dataGrid1.FieldSettings.ExpandableFieldRecordExpansionMode = ExpandableFieldRecordExpansionMode.ExpandAlways;
I attached the example project.
The crux of the matter is, i need a different single relation for every row.
I'm working on an example project. By the way, can you see my screenshots?
"When there is more than one Field it displays these presenters so the user can tell which is which."
Yes i understand this, but in my case 1 row can only use 1 relation, so there is no need for the user to know which relation is used. Can i somehow turn this display feature off?