Click here to Skip to main content
15,881,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am trying to bind my control to two collections (bind the header of a groupbox to a collection and the content to another associated collection).
here is the situation in detail:

I have two tables:
Employees(empID, EmpName, empDepartmentId)
and
Departments(depID, depName)

I want to bind these to a flow layout control (devexpress) so that the control's groupboxes headers show the department Name and the content shows employees in the department

The code below works fine for the header but I can't figure out how to add the employee names.

I put ??? where I should bind to the Employees.

I think I have to bind to a collection that is filtered with the Id of the current Item's depID property but I don't know how, something like this:
C#
XPCollection<employee> DepEmployees = new XPCollection<employee>(new BinaryOperator("empDepartmentId", currentgroupbox.depID????? , BinaryOperatorType.Equal));

and then in Xaml:

<TextBlock Text="{Binding DepEmployees , RelativeSource={RelativeSource AncestorType={x:Type local:MainWindow}}}"/>


What I have tried:

Xaml:

<dxlc:FlowLayoutControl
            x:Name="Departments"
            Background="Transparent"
            ItemSpace="12"
            LayerSpace="12"
            Orientation="Horizontal">
<dxlc:FlowLayoutControl.ItemTemplate>
                <DataTemplate>
                    <dxlc:GroupBox
                        Width="200"
                        Height="250"
                        Content="{Binding}"
                        Cursor="Hand"
                        FontFamily="Segoe UI Light"
                        FontSize="14"
                        Header="{Binding}"
                        MaximizeElementVisibility="Visible"
                        Padding="0">
                        
                        <dxlc:GroupBox.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock Margin="1">
                                    <Run FontFamily="Segoe UI" Text="{Binding depName}" />
                                    <Run Text=" , " />
                                    <Run Text="{Binding depID}" />
                                </TextBlock>
                            </DataTemplate>
                        </dxlc:GroupBox.HeaderTemplate>
                        <dxlc:GroupBox.ContentTemplate>
                            <DataTemplate>
                                
                                    <TextBlock Text="{Binding empName ???????}" />
                                
                            </DataTemplate>
                        </dxlc:GroupBox.ContentTemplate>
                    </dxlc:GroupBox>
                </DataTemplate>
            </dxlc:FlowLayoutControl.ItemTemplate>
        </dxlc:FlowLayoutControl>


CSharp

C#
Departments.ItemsSourcenew = XPCollection(typeof(Departments));
Posted
Updated 3-Jan-20 23:22pm
v3

1 solution

You need to define a One-to-Many Relationship as shown in the examples here:
Relationships Between Objects | eXpress Persistent Objects | DevExpress Documentation[^]

Also see: XPCollection Concepts | eXpress Persistent Objects | DevExpress Documentation[^]

For WPF applications it is recommended to use ObservableCollection instead of XPCollection, see second example here: T838546 - XPO Best Practices in WPF applications | DevExpress Support Center[^]
 
Share this answer
 
v3
Comments
izz moe 4-Jan-20 11:20am    
The problem is not in the xpcollection itself, imagine in this situation you want to make for every department a listbox that contains the employees of every department.. the list boxes are bound to the departments but every list box needs to filter the employees table by the department id it belongs to, my problem is binding every listbox since they are created using itemtemplate.
RickZeeland 4-Jan-20 12:56pm    
Well, it seems there is not enough XPO expertise on CodeProject to help you, maybe you should try on a DevExpress forum, good luck !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900