Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Master/Detail Grid

Sort Posts: Previous Next
  •  04-29-2008, 10:45 AM Post no. 11829

    Master/Detail Grid

    Hello,

    I am trying to build a master details grid but didnt succeed here is my code listing:

     

    [CODE] 

    <Page x:Class="TimeSheetApplication.AssignmentsPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"
        Title="Assignments" Loaded="AssignmentsPage_Loaded">
        <Grid>
            <DockPanel>
                <ToolBar Height="26" Name="mainToolBar" DockPanel.Dock="Top">
                    <Button>Add</Button>
                    <Button>Remove</Button>
                </ToolBar>
                <Grid xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid">
                    <Grid.Resources>
                        <xcdg:DataGridCollectionViewSource x:Key="cvs_assignments"
                                           Source="{Binding Source={x:Static Application.Current},
                                                            Path=Assignments}"/>
                        <xcdg:IndexToOddConverter x:Key="rowIndexConverter" />

                        <Style x:Key="alternatingDataRowStyle" TargetType="{x:Type xcdg:DataRow}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},
                                      Path=(xcdg:DataGridVirtualizingPanel.ItemIndex),
                                      Converter={StaticResource rowIndexConverter}}"
                            Value="True">
                                    <Setter Property="Background" Value="AliceBlue"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Grid.Resources>
                    <DockPanel>
                        <Button Content="Collapse All Details" Click="Button_Click" DockPanel.Dock="Top"/>
                        <xcdg:DataGridControl x:Name="AssignmentsGrid" ItemsSource="{Binding Source={StaticResource cvs_assignments}}" NavigationBehavior="RowOnly" AutoCreateDetailConfigurations="True" AllowDetailToggle="True" EditTriggers="BeginEditCommand, ClickOnCurrentCell, SingleClick, CellIsCurrent, ActivationGesture, RowIsCurrent">
                        <xcdg:DataGridControl.View>
                            <xcdg:TableView UseDefaultHeadersFooters="False">
                                    <xcdg:TableView.Headers>
                                        <DataTemplate>
                                            <xcdg:InsertionRow />
                                        </DataTemplate>
                                    </xcdg:TableView.Headers>
                                    <xcdg:TableView.FixedHeaders>
                                    <DataTemplate>
                                        <xcdg:HierarchicalGroupByControl xcdg:TableView.CanScrollHorizontally="False" />
                                    </DataTemplate>
                                    <DataTemplate>
                                        <xcdg:ColumnManagerRow />
                                    </DataTemplate>
                                </xcdg:TableView.FixedHeaders>
                                <xcdg:TableView.Theme>
                                    <xcdg:AeroNormalColorTheme />
                                </xcdg:TableView.Theme>
                            </xcdg:TableView>
                        </xcdg:DataGridControl.View>
                        <xcdg:DataGridControl.DetailConfigurations>
                            <xcdg:DetailConfiguration RelationName="FK_Tasks_Assignments"
                                     Title="Assignments_Tasks"
                                     ItemContainerStyle="{StaticResource alternatingDataRowStyle}" AutoCreateDetailConfigurations="True">
                                <xcdg:DetailConfiguration.Columns>
                                    <xcdg:Column FieldName="assignmentId" Visible="False" />
                                </xcdg:DetailConfiguration.Columns>
                            </xcdg:DetailConfiguration>
                        </xcdg:DataGridControl.DetailConfigurations>
                    </xcdg:DataGridControl>
                    </DockPanel>
                </Grid>
            </DockPanel>
        </Grid>
    </Page>
    [/CODE]

     

    [CODE]

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using System.Data;
    using TimeSheetDAL;
    using Xceed.Wpf.DataGrid;
    using Xceed.Wpf.DataGrid.Converters;
    using Xceed.Wpf.DataGrid.Print;
    using Xceed.Wpf.DataGrid.Stats;
    using Xceed.Wpf.DataGrid.ValidationRules;
    using Xceed.Wpf.DataGrid.Views;
    using Xceed.Wpf.Controls;
    using Xceed.Wpf.DataGrid.ThemePack;

    namespace TimeSheetApplication
    {
        /// <summary>
        /// Interaction logic for Assignments.xaml
        /// </summary>
        public partial class AssignmentsPage : Page
        {

            public AssignmentsPage()
            {
                InitializeComponent();
            }

            private void AssignmentsPage_Loaded(object sender, RoutedEventArgs e)
            {
                TimeSheetDAL.TimeSheetDAL dal = TimeSheetDAL.TimeSheetDAL.Instance;
                dal.assignmentsTableAdapter.Fill(dal.timeSheetDataSet.Assignments);
                dal.tasksTableAdapter.Fill(dal.timeSheetDataSet.Tasks);

                this.AssignmentsGrid.ItemsSource = dal.timeSheetDataSet.Assignments.DefaultView;
               
            }

            private void Button_Click(object sender, RoutedEventArgs e)
            {
                DataGridContext rootContext = DataGridControl.GetDataGridContext(this.AssignmentsGrid);

                List<DataGridContext> childContexts = new List<DataGridContext>(this.AssignmentsGrid.GetChildContexts());

                foreach (DataGridContext context in childContexts)
                {
                    context.ParentDataGridContext.CollapseDetails(context.ParentItem);
                }
            }
        }
    }
    [/CODE]

     

    I have the Master Grid working fine which is corresponding to Assignments, but the detail grid doesnt show which is corresponding to Tasks. what could be missing in my code?
     

  •  04-29-2008, 11:12 AM Post no. 11830 in reply to 11829

    Re: Master/Detail Grid

    Master/detail is supported through the DataGridCollectionView[Source]. In the example you provide, you initially bind the grid to the DataGridCollectionViewSource that has the Assignments as a source; however, in the Loaded event, you then reassign Assignment's DefaultView to the grid's ItemsSource property, removing the master/detail capabilities.

    If you want to use code-behind to set the ItemsSource, then you should wrap your source in a DataGridCollectionView  before assigning it to the ItemsSource property:

    DataGridCollectionView view = new DataGridCollectionView( dal.timeSheetDataSet.Assignments.DefaultView );
    this.AssignmentsGrid.ItemsSource = view;


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  04-29-2008, 1:34 PM Post no. 11837 in reply to 11830

    Re: Master/Detail Grid

    Great now it works

    Thank you 

  •  08-06-2008, 6:45 PM Post no. 13935 in reply to 11837

    Re: Master/Detail Grid

    Could you please explain this in detail.

    if possible could you please share working code so that i can have more understanding.

    I have copied the code but it's not working means expanding is not happening.
     

  •  10-13-2008, 5:33 PM Post no. 16043 in reply to 11830

    Re: Master/Detail Grid

    How do I raise the event on the expand / collapse for the master-detail grid. Does visible property is of any help?
  •  10-14-2008, 9:52 AM Post no. 16065 in reply to 16043

    Re: Master/Detail Grid

    You could monitor the Visible property of each DetailConfiguration by creating a ValueChanged handler for the Visible property, which is a dependency property.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  10-14-2008, 9:57 AM Post no. 16068 in reply to 16065

    Re: Master/Detail Grid

    But instead of doing this for every detail configuration, is there is a generic way where I can raise the event for Expand / Collapse on the grid level and get the detail configuration as a event argument?

     

  •  10-14-2008, 10:45 AM Post no. 16070 in reply to 16068

    Re: Master/Detail Grid

    No. The detail configuration is applied to all same-level details; therefore, they will all raise the value-changed event for the Visible property.
    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  10-14-2008, 11:10 AM Post no. 16077 in reply to 16070

    Re: Master/Detail Grid

    I couldnt get this working. please validate my code

     <xcdg:DataGridControl.DetailConfigurations>

    <xcdg:DetailConfiguration RelationName="Notes_IEnumerable"

    UseDefaultHeadersFooters="False"

    AutoCreateColumns="False" x:Name="DetailConfig" >

    <xcdg:DetailConfiguration.Columns>

    <xcdg:Column FieldName="Notes"

    Visible="True"

    Width="730"

    TextWrapping="Wrap"/>

    </xcdg:DetailConfiguration.Columns>

    </xcdg:DetailConfiguration>

    </xcdg:DataGridControl.DetailConfigurations>

     

    Private _visibleChangedDescriptor As DependencyPropertyDescriptor

    Public Sub OnVisibleChanged(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Private Sub CommunicationTab_Initialized(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Initialized

    _visibleChangedDescriptor = DependencyPropertyDescriptor.FromProperty(DetailConfiguration.VisibleProperty, GetType(DetailConfiguration))

    _visibleChangedDescriptor.AddValueChanged(Me.DetailConfig, New EventHandler(AddressOf OnVisibleChanged))

    End Sub

     

  •  10-14-2008, 11:14 AM Post no. 16078 in reply to 16077

    Re: Master/Detail Grid

    Where is this code located? Are you getting any errors? You could also use the DataGridControl or DataGridContext's AreDetailsExpanded method to know if same-level details are expanded. 


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
  •  10-14-2008, 11:20 AM Post no. 16080 in reply to 16078

    Re: Master/Detail Grid

    No I am not getting any errors. The code is as shown above in the thread. The event is simply not getting fired. I need an event and I cannot survive with the method
  •  10-15-2008, 8:42 AM Post no. 16109 in reply to 16080

    Re: Master/Detail Grid

    OK, after speaking with one of the developers I realized that I was not giving you the correct information. The Visible property is used to determine if the detail will be visible or not once it is expanded. Its state does not changed. That said, unfortunately, there is currently no way to know when a detail's expansion state has changed. I will add a feature request.

    I apologize for any inconveniences this may have caused. 


    Technical Writer - Xceed Software

    Of all the things I've lost, I miss my mind the most. - Mark Twain
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.