I am trying to create multiple levels of headers, but I do not want corresponding levels of data in my grid. Is there a way to override one of the presenters or another way to accomplish this?
For example, the grid would look like:
(Please use the below HTML to see a table representation as it does not show correctly in my post)
<TABLE class="" border=1><TBODY><TR><TD class="" rowSpan=2>Distributor Name</TD><TD class="" colSpan=3>Additional Info</TD></TR><TR><TD class="">Level</TD><TD class="">Position</TD><TD class="">Earnings</TD></TR><TR><TD class="">Sally Cinnamon</TD><TD class="">25</TD><TD class="">Supervisor</TD><TD class="">$25.00</TD></TR><TR><TD class="">Jimmy John</TD><TD class="">24</TD><TD class="">Supervisor</TD><TD class="">$20.00</TD></TR></TBODY></TABLE>
So, only Distributor Name, Level, Position, and Earnings map to actual data. Additional Info is just an extra heading. I have tried to do this using the rowspan and columnspan properties, and they create a grid that looks like this:
<TABLE class="" border=1><TBODY><TR><TD class="" rowSpan=2>Distributor Name</TD><TD class="" colSpan=3>Additional Info</TD></TR><TR><TD class="">Level</TD><TD class="">Position</TD><TD class="">Earnings</TD></TR><TR><TD class="" rowSpan=2>Sally Cinnamon</TD><TD class="" colSpan=3> </TD></TR><TR><TD class="">25</TD><TD class="">Supervisor</TD><TD class="">$25.00</TD></TR><TR><TD class="" rowSpan=2>Jimmy John</TD><TD class="" colSpan=3> </TD></TR><TR><TD class="">24</TD><TD class="">Supervisor</TD><TD class="">$20.00</TD></TR></TBODY></TABLE>
Is there any way to get a grid that resembles the first table instead?
Thank you!
The way you accomplish this is to turn off the auto arrangement of cells (requiring you to specify the Row/Column and span location for each field), add an UnboundField that represents 'Additional Info' and set its CellContentAlignment to 'LabelOnly'. Here is some sample code:
<igDP:XamDataPresenter.FieldLayoutSettings>
</igDP:XamDataPresenter.FieldLayoutSettings>
<igDP:FieldLayout>
<igDP:Field Name="Name" Row="1" Column="0"/>
<igDP:UnboundField Name="Additional Info" Row="0" Column="0" ColumnSpan="3">
<igDP:FieldSettings CellContentAlignment="LabelOnly"/>
</igDP:UnboundField>
</igDP:FieldLayout>
</igDP:XamDataPresenter>
I Hope this helps.
I just realized that the code snippet I just posted ends up leaving space in every record for the unbound field which is probably not wat you want. To get rid of the space change the definitsion of the unbound field as follows:
<igDP:UnboundField.Settings>
<igDP:FieldSettings.CellValuePresenterStyle>
<Setter Property="Visibility" Value="Collapsed"/>
</igDP:FieldSettings.CellValuePresenterStyle>
</igDP:UnboundField.Settings>
Hi Joe,
Thanks for your help. Unfortunately, this does not work for me... When I use the following XAML, I get the error "The attachable property CellValuePresenterStyle was not found in type field settings"
<igDP:XamDataGrid Grid.Row="0" Grid.ColumnSpan="3" x:Name="XamDataGrid1"
DataSource="{Binding Source={StaticResource OrderData}, XPath=Order}">
<igDP:XamDataGrid.FieldLayouts>
<igDP:FieldLayout.Settings>
<igDP:FieldLayoutSettings AutoArrangeCells="Never" AutoGenerateFields="False"/>
</igDP:FieldLayout.Settings>
<igDP:FieldLayout.Fields>
<igDP:UnboundField Name="Grouping" Row="0" ColumnSpan="2">
<Style TargetType="{x:Type igDP:CellValuePresenter}">
</Style>
<igDP:Field Name="CostPerUnit" Row="1" Column="0"/>
<igDP:Field Name="Quantity" Row="1" Column="1"/>
<igDP:Field Name="Discount" Row="1" Column="2"/>
<igDP:Field Name="ShipAndHandle" Row="1" Column="3"/>
</igDP:FieldLayout.Fields>
</igDP:XamDataGrid.FieldLayouts>
</igDP:XamDataGrid>
So, I tried changing it to be:
x:Name="XamDataGrid1"
<igDP:XamDataGrid.Resources>
<Style TargetType="{x:Type igDP:CellValuePresenter}" x:Key="invisibleData">
</igDP:XamDataGrid.Resources>
<igDP:FieldSettings CellValuePresenterStyle="invisibleData"></igDP:FieldSettings>
In this instance, I do not get any error in the XAML, but I get an error which says
"The name InitializeComponent does not exist in the current context" This seems to be the generic error message which occurs when there is a problem creating the objects described by the XAML.
Is there something I am doing wrong?
Thank you, Arwin
Got it. Thank you!
Arwin,
It looks like you have some badly formed xaml in the first approach Replace the following lines:
with these:
<igDP:FieldSettings CellContentAlignment="LabelOnly">
</igDP:FieldSettings>
In the second approach you need to use a StaticResource to access the key and combine the 2 attributes inside one FieldSettings tag, e.g.
<igDP:FieldSettings CellValuePresenterStyle="{StaticResource invisibleData}" CellContentAlignment="LabelOnly"/>