Hi, I'm using XamDataGrid to display a bonds grouped by a bid list (see the image below). Sometimes I need to display bid lists that are empty (i.e. contain no bonds). To create an empty bid list grouping I insert a "special" fake bond into it. But in this case I want the grouping to show a special message spanning the columns (like the first groping in the image below). What is my best strategy to achieve something like this with XamDataGrid? Thanks!
Hello,
I am not sure how you are creating a dummy group, but I am adding an unique dummy item so that the XamDataGrids creates a group for it only. Then I am applying a custom template for that record (only if its parent is a GroupByRecord - i.e. is in a group). I have attached my sample, but here is some of the code that I am using :
27 xamDataGrid1.FieldLayoutSettings.DataRecordPresenterStyleSelector = new DRPStyleSelector(xamDataGrid1);
...
32 public class DRPStyleSelector : StyleSelector
33 {
34 private XamDataGrid _grid;
35 public DRPStyleSelector(XamDataGrid grid)
36 {
37 this._grid = grid;
38 }
39 public override Style SelectStyle(object item, DependencyObject container)
40 {
41 DataRecord dr = item as DataRecord;
42 Bid dataItem;
43 if (dr != null)
44 {
45 dataItem = dr.DataItem as Bid;
46 // a Bid with a negative Id is a dummy bid
47 if (dr.ParentRecord is GroupByRecord && dataItem != null && dataItem.Id < 0)
48 {
49 return _grid.Resources["DRPDummyStyle"] as Style;
50 }
51 }
52
53 return base.SelectStyle(item, container);
54 }
55 }
where DRPDummyStyle is a simple style for the data record presenter:
<Style TargetType="{x:Type igDP:DataRecordPresenter}" x:Key="DRPDummyStyle">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type igDP:DataRecordPresenter}">
<Grid>
<TextBlock Text="Drag Bids here..." FontSize="16" Margin="10,10,10,20"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Here is what I got :
Hi Alex, thanks a lot. This is very close to what I need. The one problem with your example I found is that when you collapse the "special" group and uncollapse it the style reverts to main one (with columns for every field). I'm using v9.2 of the XamDataGrid. Is there a workaround for that?