Welcome to the Xceed Community | Help
Community Search  
More Search Options

Master / Detail with a strongly typed dataset

Sort Posts: Previous Next
  •  01-16-2009, 10:18 AM Post no. 17930

    Master / Detail with a strongly typed dataset

    I'm trying to create a master / detail grid with a strongy typed dataset. The dataset contains two tables and the relationship between them. The xaml for the grid is.......

    <xcdg:DataGridControl Grid.Row="1" AutoCreateColumns="False" Name="dgAdverts" ReadOnly="True" SelectionMode="Single" EditTriggers="None" NavigationBehavior="RowOnly" Margin="0,0,0,5" AutoCreateDetailConfigurations="False" AllowDetailToggle="True">

    <xcdg:DataGridControl.Resources>

    <Style TargetType="ScrollBar">

    <Setter Property="Visibility" Value="Hidden"/>

    </Style>

    </xcdg:DataGridControl.Resources>

    <xcdg:DataGridControl.View>

    <xcdg:TableView UseDefaultHeadersFooters="False" ShowFixedColumnSplitter="False" ColumnStretchMode="All">

    <xcdg:TableView.FixedHeaders>

    <DataTemplate>

    <xcdg:ColumnManagerRow AllowAutoFilter="False" AllowSort="True" />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    <xcdg:TableView.Theme>

    <xcdg:Office2007BlackTheme />

    </xcdg:TableView.Theme>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="[BoardName]" Title="Job Board" IsMainColumn="True" />

    <xcdg:Column FieldName="[NumAdverts]" Title="Adverts" />

    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.DetailConfigurations>

    <xcdg:DetailConfiguration RelationName="JobBoards_Adverts">

    <xcdg:DetailConfiguration.Columns>

    <xcdg:Column FieldName="AdvertStatus" Title="Advert Status" />

    <xcdg:Column FieldName="VacancyReference" Title="Vacancy Reference" />

    <xcdg:Column FieldName="StartDate" Title="Post Date" />

    <xcdg:Column FieldName="EndDate" Title="Expiry Date" />

    </xcdg:DetailConfiguration.Columns>

    </xcdg:DetailConfiguration>

    </xcdg:DataGridControl.DetailConfigurations>

    </xcdg:DataGridControl>

     

    I populate the grid with the following code

    public void LoadAdvertsGrid()

    {

    using (AdvertServices aServ = new AdvertServices())

    {

    _Ads = aServ.LoadAdvertsForVacancy(_CurrentVacancyID);

    DataGridCollectionView ColView = new DataGridCollectionView(_Ads.Tables);

    dgAdverts.ItemsSource = ColView;

    }

    }

     

    For a dataset with two tables with one row in each with a relationship between the two my grid display one master row correctly plus one master row that is completely blank even though there is only one master record in the data. When I expand the master rows they both show the correct column headers but no data at all. I'd be grateful for any ideas that could help me out with this problem.

     

    Thanks

     

    Paul

  •  01-19-2009, 4:55 AM Post no. 17980 in reply to 17930

    Re: Master / Detail with a strongly typed dataset

    I'm still having issues with this master / detail problem. If I set AutoCreateDetailConfigurations="True" then for a dataset with one master record and one child record I get two master rows, one blank the other populated correctly. The populated master row then has a blank detail row and the blank master row has a populated detail row. I'm wondering if this could be something to do with the relationship in the dataset. Is there something that I need to do other than

    <xcdg:DetailConfiguration RelationName="JobBoards_Adverts">

     

    In order to make sure that the relationship is set up correctly in the grid?

     

    Thanks for any help you can offer.

    Paul

  •  01-20-2009, 7:23 AM Post no. 18013 in reply to 17980

    Re: Master / Detail with a strongly typed dataset

    Hi, I did pretty much the same thing as you.  The only difference i can see is that i created the CollectionViewSource in Xaml bound to the master table.

    I bound my grid to that.

    Then when i set AutoCreateDetailConfiguration to True as if by magic my child grid was born.


     

  •  01-20-2009, 1:39 PM Post no. 18021 in reply to 18013

    Re: Master / Detail with a strongly typed dataset

    Thanks for the reply. I've tried using a CollectionViewSource in code and in the xaml too but I can't get it to do anything other than show one correctly populated master row with a blank detail row and one blank master row with a populated detail row rather than one master row and one detail row. I've also tried setting AutoCreateDetailConfiguration to true and it doesn't help.

    Surely someone must have done this without any problems or am I trying to do something that isn't even possible? Any kind of very basic sample to show how it's done would be appreciated. Or if anyone has any ideas as to what I could be missing that would be helpful too.

  •  01-22-2009, 7:55 AM Post no. 18058 in reply to 18021

    Re: Master / Detail with a strongly typed dataset

    All the samples seem to use the CollectionViewSource in order to get the master detail working. Does anyone have any sample code of how to do that in c#?
  •  01-22-2009, 11:23 AM Post no. 18063 in reply to 18058

    Re: Master / Detail with a strongly typed dataset

    I've not tried setting up a basic grid using a sample from the documentation and I've made a little bit of progress. I've now got the following xaml

     

    In the resources of the window :

    <xcdg:DataGridCollectionViewSource x:Key="TheData" Source="{Binding ElementName=TestGrid, Path=Data}" />

    The grid itself :

     

    <xcdg:DataGridControl x:Name="AdvertGrid" ItemsSource="{Binding Source={StaticResource TheData}}" AutoCreateDetailConfigurations="True" ReadOnly="True" EditTriggers="None">

    <xcdg:DataGridControl.View>

    <xcdg:TableView ShowFixedColumnSplitter="False" UseDefaultHeadersFooters="False">

    <xcdg:TableView.FixedHeaders>

    <DataTemplate>

    <xcdg:ColumnManagerRow />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="VacancyID" Visible="False" IsMainColumn="True" />

    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.DetailConfigurations>

    <xcdg:DetailConfiguration RelationName="JobBoards_Adverts" Title="Job Board Adverts">

    <xcdg:DetailConfiguration.Columns>

    <xcdg:Column FieldName="AdvertID" Visible="False" />

    </xcdg:DetailConfiguration.Columns>

    </xcdg:DetailConfiguration>

    </xcdg:DataGridControl.DetailConfigurations>

    </xcdg:DataGridControl>

     

     This gives me a blank row that I can expand which then has two child rows. One for each of the tables which is obviously wrong. I can then expand the row containing the master data and it correctly has the detail data below it so this part seems to work but the rest of the grid seems a bit strange. Any ideas as to what I'm doing wrong would be very helpful. Thanks

  •  01-26-2009, 5:28 AM Post no. 18108 in reply to 18063

    Re: Master / Detail with a strongly typed dataset

    Areyou sure the Data is correct and that your relationship is correct in the Dataset?

    Sorry i can't be more help.  I'm no expert.  Maybe somebody who has had a similar issue and resolved it will reply soon.  It sounds to me like you doing everything ok.

     

     

  •  01-27-2009, 11:07 AM Post no. 18161 in reply to 18108

    Re: Master / Detail with a strongly typed dataset

    I'm pretty sure that the data is ok. I've checked and re-checked it and the dataset seems to be populated correctly and the relationship setup ok.

    I've made a little progress though. I've now got a grid that has the master row correctly displayed but with no data and the detail row is correctly linked and displayed but there is no data showing. I'm wondering if I'm doing something wrong with the setup of the columns or the syntax of the binding. I've posted the xaml below so if anyone can spot any problems then please let me know.

     

    <custom:DocumentContent x:Class="RecMan.GridTest"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    xmlns:custom="clr-namespace:DockingLibrary;assembly=DockingLibrary"

    xmlns:local="clr-namespace:RecMan.Controls"

    xmlns:recman="clr-namespace:RecMan"

    xmlns:xcdg="http://schemas.xceed.com/wpf/xaml/datagrid"

    Title="Role Window" x:Name="TestGrid">

    <custom:DocumentContent.Resources>

    <xcdg:DataGridCollectionViewSource x:Key="TheData" Source="{Binding RelativeSource={RelativeSource AncestorType={x:Type custom:DocumentContent}}, Path=Data, Mode=OneWay}" />

    </custom:DocumentContent.Resources>

    <xcdg:DataGridControl x:Name="AdvertGrid" ItemsSource="{Binding Source={StaticResource TheData}}" AutoCreateDetailConfigurations="False" ReadOnly="True" EditTriggers="None">

    <xcdg:DataGridControl.View>

    <xcdg:TableView ShowFixedColumnSplitter="False" UseDefaultHeadersFooters="False">

    <xcdg:TableView.FixedHeaders>

    <DataTemplate>

    <xcdg:ColumnManagerRow />

    </DataTemplate>

    </xcdg:TableView.FixedHeaders>

    </xcdg:TableView>

    </xcdg:DataGridControl.View>

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName="BoardName" Title="Job Board" IsMainColumn="True" />

    <xcdg:Column FieldName="NumAdverts" Title="Adverts" />

    </xcdg:DataGridControl.Columns>

    <xcdg:DataGridControl.DetailConfigurations>

    <xcdg:DetailConfiguration RelationName="JobBoards_Adverts" Title="Adverts">

    <xcdg:DetailConfiguration.Columns>

    <xcdg:Column FieldName="AdvertStatus" Title="Status" />

    <xcdg:Column FieldName="VacancyReference" Title="Ref" />

    <xcdg:Column FieldName="StartDate" Title="Start" />

    <xcdg:Column FieldName="EndDate" Title="End" />

    </xcdg:DetailConfiguration.Columns>

    </xcdg:DetailConfiguration>

    </xcdg:DataGridControl.DetailConfigurations>

    </xcdg:DataGridControl>

    </custom:DocumentContent>

     

    Paul

  •  01-28-2009, 5:23 AM Post no. 18190 in reply to 18161

    Re: Master / Detail with a strongly typed dataset

    If I have a look in the output window after running the grid using the xaml from above I get the following binding error. Does anyone have an idea what I'm doing wrong?

    System.Windows.Data Error: 39 : BindingExpression path error: 'BoardName' property not found on 'object' ''DataViewManagerListItemTypeDescriptor' (HashCode=44249191)'. BindingExpression:Path=BoardName; DataItem='DataViewManagerListItemTypeDescriptor' (HashCode=44249191); target element is 'DataCell' (Name=''); target property is 'Content' (type 'Object')

     

  •  01-29-2009, 9:14 AM Post no. 18255 in reply to 18190

    Re: Master / Detail with a strongly typed dataset

    Here is an Example of a Detail Class you should create to get the detail items (I dont like autoCreate)

    public class PartsDetail : DataGridDetailDescription
        {
            public PartsDetail()
            {
                RelationName = "Parts";
                Title = "Parts to cut";

                ItemProperties.Add(new DataGridItemProperty("quan", typeof(int)));
                ItemProperties.Add(new DataGridItemProperty("Job", "Job", typeof(string)));
                ItemProperties.Add(new DataGridItemProperty("Mark", "mark", typeof(string)));
                ItemProperties.Add(new DataGridItemProperty("Cut", "cut", typeof(bool)));
                ItemProperties.Add(new DataGridItemProperty("Locked", "locked", typeof(bool)));
                ItemProperties.Add(new DataGridItemProperty("Dont Cut", "DontCut", typeof(bool)));
                ItemProperties.Add(new DataGridItemProperty("length", typeof(int)));

                Xceed.Wpf.DataGrid.Stats.SumFunction totQ = new Xceed.Wpf.DataGrid.Stats.SumFunction("totQuan", "quan");
                LengthSumStatFunction totL = new LengthSumStatFunction("totLength", "length");
                this.StatFunctions.Add(totQ);
                this.StatFunctions.Add(totL);
            }
            protected override System.Collections.IEnumerable GetDetailsForParentItem(DataGridCollectionViewBase parentCollectionView, object parentItem)
            {
                Material mat = parentItem as Material;
                if (mat != null)
                {

                    //Here is Where you get the Detail Items for object parentItem.This is on Demand so this only runs when the Details are expanded

                    DataGridCollectionView view = new DataGridCollectionView(mat.Parts);
                    return new DataGridCollectionView(view);

                    //another possible way to set this up is to use Linq to Datasets and retrieve the ID of the parentItem then query a dataset for children?
                }
                return new Part[0];

            }

        }

     

    //Just so you know the Sum Function never worked and I am still figuring out how to get Stat Functions Working

  •  01-29-2009, 9:20 AM Post no. 18256 in reply to 18255

    Re: Master / Detail with a strongly typed dataset

    And Here is how I use it.

                var vStock = new DataGridCollectionView(whip.Stock);//you must use a DataGridCollectionView to use MasterDetail
                vStock.DetailDescriptions.Add(new PartsDetail());//Add the DetailDescription to the DataGridCollectionView
                dgStock.ItemsSource = vStock;//set the source on the DataGridControl
     

    I dont use DataSets(and dont know how with Xceed) but collections of Objects from my LightSpeed ORM. So you will have to figure out how they differ

  •  01-29-2009, 9:22 AM Post no. 18257 in reply to 18256

    Re: Master / Detail with a strongly typed dataset

    And here is my Xaml to set up the Grid(I set up the main grid automatically per type with some classes I wrote but Details I still set up manually)

    ------------------------------------

    <Windows:CustomDataGridControl Name="dgStock" Tag="Cutting-Stock">
                        <Windows:CustomDataGridControl.Resources>
                            <ResourceDictionary Source="MaterialStyles.xaml"/>
                        </Windows:CustomDataGridControl.Resources>
                        <xcdg:DataGridControl.DetailConfigurations>
                            <xcdg:DetailConfiguration RelationName="Parts" AutoCreateColumns="False">
                                <xcdg:DetailConfiguration.Columns>
                                    <xcdg:Column Title="Qty" FieldName="quan" Width="50" ReadOnly="True" CellContentTemplate="{StaticResource StringDataTemplate}"/>
                                    <xcdg:Column Title="Mark" FieldName="mark" Width="75" ReadOnly="True" CellContentTemplate="{StaticResource StringDataTemplate}"/>
                                    <xcdg:Column Title="Job" FieldName="Job" Width="100" ReadOnly="True" CellContentTemplate="{StaticResource StringDataTemplate}"/>
                                    <xcdg:Column Title="Length" FieldName="length" Width="100" ReadOnly="True" CellContentTemplate="{StaticResource LengthCellTemplate}"/>
                                    <xcdg:Column Title="Cut" FieldName="cut" Width="100" ReadOnly="True" CellContentTemplate="{StaticResource BoolCellDataTemplate}"/>
                                </xcdg:DetailConfiguration.Columns>
                            </xcdg:DetailConfiguration>
                        </xcdg:DataGridControl.DetailConfigurations>
                    </Windows:CustomDataGridControl>

     

    ----------------------------------------------

    I hope this helps you in setting up your Master Detail situation

  •  01-29-2009, 11:11 AM Post no. 18260 in reply to 18257

    Re: Master / Detail with a strongly typed dataset

    Thanks for the help. I've finally managed to get it working. Your code with a couple of changes was exactly what I needed.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.