We have a problem where adding showing/hiding Fields in our grid causes the grid to not restore properly from saved data.
Below is our XAML. We inherit from XamDataGrid to add some functionality on top. Notice that all fields are * width, and several are collapsed by default (the user can show/hide columns at will).
<t:NTGrid x:Name ="grdOrder" AutoFit ="False" CellContainerGenerationMode ="Recycle" GroupByAreaLocation ="None" GroupByAreaMode ="DefaultFieldLayoutOnly" InitializeRecord ="OnInitializeRecord" IsResizeDeferred ="True" Loaded ="OnGridLoaded" RecordContainerGenerationMode ="Recycle" Tag ="OrderGrid" UpdateMode ="OnUpdate" AutomationProperties.AutomationId="OrderGridTable"> <t:NTGrid.SuppressedEvents> <i:RoutedEventWrapper RoutedEvent="ie:ValueEditor.TextChanged" /> <i:RoutedEventWrapper RoutedEvent="ie:ValueEditor.ValueChanged" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.AssigningFieldLayoutToItem" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.CellActivating" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.CellActivated" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.CellDeactivating" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.DataValueChanged" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.ExecutingCommand" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.ExecutedCommand" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.InitializeCellValuePresenter" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.RecordActivating" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.RecordActivated" /> <i:RoutedEventWrapper RoutedEvent="i:DataPresenterBase.RecordDeactivating" /> </t:NTGrid.SuppressedEvents> <t:NTGrid.FieldSettings> <i:FieldSettings AllowEdit ="False" CellClickAction ="SelectRecord" CellValuePresenterStyle ="{StaticResource OrderGridCellValuePresenter}" ForceCellVirtualization ="True" GroupByRecordPresenterStyle ="{StaticResource OrdersGridGroupByRecordPresenter}" LabelClickAction ="SortByOneFieldOnly" LabelTextAlignment ="Center" LabelTextWrapping ="NoWrap" /> </t:NTGrid.FieldSettings> <t:NTGrid.FieldLayoutSettings> <i:FieldLayoutSettings AllowClipboardOperations ="Copy" AllowDelete ="False" AllowFieldMoving ="WithinLogicalRow" AutoFitMode ="OnlyWithVisibleStarFields" AutoGenerateFields ="False" CopyFieldLabelsToClipboard ="True" DataRecordPresenterStyle ="{StaticResource SimpleDataRecordPresenter}" DataRecordSizingMode ="Fixed" HeaderPlacementInGroupBy ="OnTopOnly" HeaderPrefixAreaDisplayMode ="None" LabelLocation ="SeparateHeader" MaxSelectedRecords ="1" RecordSelectorLocation ="None" SelectionTypeCell ="None" SelectionTypeRecord ="Single" /> </t:NTGrid.FieldLayoutSettings> <t:NTGrid.FieldLayouts> <i:FieldLayout Key="MainFieldLayout"> <i:FieldLayout.Fields> <i:Field Name="Instrument" Width="*" FixedLocation="FixedToNearEdge"/> <i:Field Name="StrategyId" Width="*" FixedLocation="FixedToNearEdge" Visibility="Collapsed"/> <i:Field Name="OrderAction" Width="*" /> <i:Field Name="OrderType" Width="*" /> <i:Field Name="TotalQuantity" Width="*" /> <i:Field Name="LimitPrice" Width="*"/> <i:Field Name="StopPrice" Width="*"/> <i:Field Name="Price" Visibility="Collapsed" Width="*"/> <i:Field Name="OrderStateString" Width="*"/> <i:Field Name="Filled" Width="*"> <i:Field Name="AverageFillPrice" Width="*" /> <i:Field Name="Remaining" Width="*" /> <i:Field Name="OrderName" Width="*" /> <i:Field Name="StrategyString" Width="*"/> <i:Field Name="OneCancelsOther" Width="*" /> <i:Field Name="TimeInForce" Width="*" /> <i:Field Name="Account" Width="*"/> <i:Field Name="AccountName" Visibility="Collapsed" Width="*"/> <i:Field Name="OrderId" Width="*" /> <i:Field Name="Time" Width="*"/ > <i:Field Name="+" BindingType="Unbound" Label="{Resx ResxName=NinjaTrader.Gui.AccountData.OrderGrid, Key=GuiOrderGridIncrease}" Width="*" Visibility="Collapsed"> <i:Field.Settings> <i:FieldSettings CellValuePresenterStyle="{StaticResource OrderGridIncreaseStyle}" /> </i:Field.Settings> </i:Field> <i:Field Name="-" BindingType="Unbound" Label="{Resx ResxName=NinjaTrader.Gui.AccountData.OrderGrid, Key=GuiOrderGridDecrease}" Width="*" Visibility="Collapsed"> <i:Field.Settings> <i:FieldSettings CellValuePresenterStyle="{StaticResource OrderGridDecreaseStyle}" /> </i:Field.Settings> </i:Field> <i:Field Name="X" BindingType="Unbound" Label="{Resx ResxName=NinjaTrader.Gui.Resource, Key=GuiCancel}" Width="*"> <i:Field.Settings> <i:FieldSettings CellValuePresenterStyle="{StaticResource OrderGridCancelStyle}" /> </i:Field.Settings> </i:Field> </i:FieldLayout.Fields> </i:FieldLayout> </t:NTGrid.FieldLayouts></t:NTGrid>
Below is how the grid looks by default with no records:
Now say the user shows TWO of the columns that are collapsed by default, and resizes ONE of them (in this case, Increase was widened by the user):
Now, SaveCustomizations() is called when the program closes, and generates the following XML (Notice that the column named "-" has NO cell or label width in the XML):
<?xml version="1.0" encoding="utf-8"?><xamDataPresenter version="15.1.20151.2055" formatVersion="1.8"> <fieldLayouts> <fieldLayout key="MainFieldLayout" orientation="Vertical" fieldList="Instrument, StrategyId;Int64, OrderAction, OrderType, TotalQuantity;Int32, LimitPrice, StopPrice, Price, OrderStateString, Filled;Int32, AverageFillPrice;Double, Remaining;Int32, OrderName, StrategyString, OneCancelsOther, TimeInForce, Account, AccountName, OrderId, Time;DateTime, +;Int32;unbound, -;Int32;unbound, X;Int32;unbound"> <fields> <field name="Instrument" extendedInfo="Instrument" FixedLocation="FixedToNearEdge" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="StrategyId" extendedInfo="StrategyId;Int64" FixedLocation="FixedToNearEdge" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" /> <field name="OrderAction" extendedInfo="OrderAction" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="OrderType" extendedInfo="OrderType" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="TotalQuantity" extendedInfo="TotalQuantity;Int32" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="LimitPrice" extendedInfo="LimitPrice" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="StopPrice" extendedInfo="StopPrice" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="Price" extendedInfo="Price" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" /> <field name="OrderStateString" extendedInfo="OrderStateString" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="Filled" extendedInfo="Filled;Int32" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="AverageFillPrice" extendedInfo="AverageFillPrice;Double" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="Remaining" extendedInfo="Remaining;Int32" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="OrderName" extendedInfo="OrderName" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="StrategyString" extendedInfo="StrategyString" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="OneCancelsOther" extendedInfo="OneCancelsOther" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="TimeInForce" extendedInfo="TimeInForce" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="Account" extendedInfo="Account" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="AccountName" extendedInfo="AccountName" Visibility="Collapsed" IgnoreFieldVisibilityOverrides="false" /> <field name="OrderId" extendedInfo="OrderId" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="Time" extendedInfo="Time;DateTime" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="+" extendedInfo="+;Int32;unbound" cellWidth="56.1" labelWidth="56.1" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="-" extendedInfo="-;Int32;unbound" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> <field name="X" extendedInfo="X;Int32;unbound" cellWidth="32.933333333333323" labelWidth="32.933333333333323" Visibility="Visible" IgnoreFieldVisibilityOverrides="false" /> </fields> </fieldLayout> </fieldLayouts>
Now, when the user restarts and we call LoadCustomizations(), this is how the grid appears:
Why is this the case, or what can we do to fix this?
I'm noticing that the screenshots appear cut off on the right side. Please Right-click on the images and View Image in order to see the entire image, thanks.
Hello Dierk,
Thank you for your post. I was looking at your issue and it seems I am missing something from your scenario. I created a sample using the information and the code snippets your provided but I am not able to reproduce the issue. I am missing the additional functionality you have implemented for the grid and also the styles you are using.
Can you please modify the sample I am attaching so the issue is reproducible?
Looking forward to hearing from you.
Sincerely,
Radko Kolev
Infragistics Inc.
www.infragistics.com/support
I am just checking if you have any further questions on this matter. Please do not hesitate to let me know if you do.
Hi Radko,
Sorry for the delay, it has been difficult to get a small, reproducible scenario.
Perhaps we can start more simply.
Run your sample application, and resize one of the columns larger or smaller.
Now open the Field chooser and enable the Increase and Decrease fields.
You should see that those two columns are very small. Why is this the case? I would expect them to match the size (or be close) of the non-resized columns.
Initially all your columns have width set to star which means all xamDataGrid’s available width will be equally distributed amongst the visible columns only. When you resize a column its preferred width get set and also the preferred width of all other visible columns with width set to star will be set too. At this moment the collapsed columns still does not participate in the process of receiving preferred width and don’t have any width. After you make a collapsed column visible there is no width left for it and it gets the minimum possible width, which is 6 pixels. You can control the minimum width for a column by setting the CellMinWidth property of the field’s settings like this:
<i:Field Name="+" BindingType="Unbound" Label="Increase" Width="*" Visibility="Collapsed">
<i:Field.Settings>
<i:FieldSettings CellMinWidth="40" />
</i:Field.Settings>
</i:Field>
If you require any further assistance, please do not hesitate to ask.
Thanks for the explanation, Radko. You mention a "preferred width." Is this something we can set or influence when setting column visibility? Or is this just the same as setting the field's Width property with a FieldLength?
Hi Dierk,
Yes, the “preferred width” is the numerical value set on the Width property.