I am displaying a 2-level data on xamDataGrid and record selector has been replaced with checkbox. anyway to increase the indent of child level.
Hello,
You can create a style for the DataRecordPresenter and set the Left Margin. If you don't set a x:key of the style, it will be applied to all of the DataRecordPresenter including the parent Records, and the there will be a margin as well. If you do set x:key, you have to apply this style to the records you choose ( child records ).
<Style TargetType="{x:Type igDP:DataRecordPresenter}" BasedOn="{x:Null}">
<Setter Property="Margin" Value="20,0,0,0"/>
</Style>
Alex.
Alex,
I tried your way but seems like it doesn't work...I attached my codes. can u pls take a look.
Thanks a lot.
<igDP:XamDataGrid Grid.Row="1" x:Name="xamDataGrid" Theme="Aero" AutoFit="False" ContextMenu="{x:Null}" SnapsToDevicePixels="True" ScrollingMode="Immediate" AllowDrop="True" RecordContainerGenerationMode="Recycle" CellContainerGenerationMode="Recycle" RecordLoadMode="LoadOnDemand" Background="Gray" DragOver="OnDragOver" Drop="OnDataDrop" PreviewMouseDown="OnXamDataGridPreviewMouseDown" PreviewMouseMove="OnXamDataGridPreviewMouseMove" PreviewMouseUp="OnXamDataGridPreviewMouseUp" MouseDoubleClick="OnGridMouseDoubleClick" MouseRightButtonDown="OnGridMouseRightButtonDown" IsGroupByAreaExpanded="False"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:RecordSelector}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type igDP:RecordSelector}"> <CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" IsChecked="{Binding Path=DataItem.IsChecked}" Checked="OnChecked" Unchecked="OnUnChecked" > </CheckBox> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type igDP:DataRecordPresenter}"> <Setter Property="Margin" Value="80,0,0,0"/> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings DataRecordSizingMode="SizedToContentAndIndividuallySizable" AutoGenerateFields="True" RecordSelectorLocation="LeftOfCellArea" ResizingMode="Default" SelectionTypeRecord="Extended" SelectionTypeField="Extended" DataRecordPresenterStyle="{StaticResource headerStyle}" DataRecordCellAreaStyle="{StaticResource rowStyle}" SelectionTypeCell="Extended"/> </igDP:XamDataGrid.FieldLayoutSettings> <igDP:XamDataGrid.FieldSettings> <igDP:FieldSettings AllowEdit="False" CellClickAction="SelectRecord" CellMinWidth="0" AllowCellVirtualization="true" CellValuePresenterStyle="{StaticResource cellStyle}" LabelPresenterStyle="{StaticResource columnStyle}"/> <!--CellValuePresenterStyle="{StaticResource cellStyle}"--> </igDP:XamDataGrid.FieldSettings> </igDP:XamDataGrid>
My boss keeps asking more.....I followed your suggestion and xmldatagrid looks like below. Now he doesn't like the increased indent push right the whole row. In other words we wanna all columns of child row,except the first column (TMS trade id), should be aligned with the ones of parent row. Is there a way to archive this?
Thanks
Hi,
I am going to propose a better solution to your first question. It is better to place that setter in a trigger and set the margin only to the records that are child, not the parent ( as the whole grid looks like is moved to the right ) so the style should look like this:
<Style.Triggers>
<Trigger Property="HasChildData" Value="False">
<Setter Property="Margin" Value="80,0,0,0"/>
</Trigger>
</Style.Triggers>
About your next question, It would not be an easy task to do this especially if the user can move the fields and resize them. If you have defined the FieldLayouts in the xaml, you can adjust their width so that the columns line up. If the fields can be moved and resized, accomplishing this task would require more manual code.
Thanks for your suggestion. It works like charm:)
For my second question how about give different margins to parent and child checkboxes? I mean change margin of parent row to (0,20,0,0) and change margin of child row to (20,0,0,0). I guess this way can visually archive my goal. Is it possible?
I am not sure that will do the trick. The margins are respectively (left, top, right, bottom) and this way you will set the top margin of the parent record. Another way to do this is to rezise the first column. Here is what I mean:
In the beginning, all of the records (parent and child) are lined up. Then you push the child record to the right with, let's say 20. So, if you resize the first cell ( take out 20 of its ActualWidth) the rest of the fields will line up again. Will this work in your scenario?
Actually I meant (0,0,20,0) not (0,20,0,0). Sorry about confusing.
About your way (decrease the first column of child row) which point can I do this? I mean in XMAL or code-behide? If Code-behide any event-handler you suggest?
Many Thanks
tried both but still no luck.....I ended up change margin of recordselector in code.
Try changing both like CellWidht and LabelWidth
Note: make sure you have defined the fields and CellWidth and LabelWidth in the xaml, otherwise these numbers will be NaN and nothing will happen.
also tried cellwidth...no luck...guess the way i set width of cell is wrong?
I wrote handler as below...But it doesn't work...any idea?
void OnInitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs e) { DataRecord dr = e.Record as DataRecord; if (dr != null && dr.ParentRecord != null) dr.Cells[0].Field.Settings.LabelWidth = dr.Cells[0].Field.Settings.LabelWidth - 20; }
If you will not be changing this cell's width, you can set it in the XAML. If you need to change it in runtime, you can use InitializeRecord event.