Hi,
I have a grid with two rows of fields. I want to link the rows together so when they are re-ordered by a user, the rows stay together.
e.g.
| Name | Address | Phone |
| Surname | Country | Area Code |
when user drags Name to Col2, Surname should also move to Col2, Row1 (e.g. stay in the same column).
Using the FieldPositionChanged event I can set the ActualPosition of the linked field easy enough and this works well when moving fields from right to left (Phone to Col1) but not the other way. Is there a better way to do this rather than looping through every single field and adjusting the ActualPosition.
I've attached an example app (vs 2015)
You can set the Visibility property on the Surname field to Collapsed. The space occupied by that field will most likely still exist, however, because you are manually positioning these headers with the Row/Column properties. You'll have to update the other fields Row/Column properties in order to make that space go away.
Is there an easy way to hide a row of headers? For example, say I want to display the Name and Surname (in the original example) but I don't want to see the surname field on the header panel.
Hi - thanks for the reply. I came up with almost identical solution also.
Hi BM,
I don't think binding will work because if you update the Column/Row property on a field it needs to be followed by a call to EnsureUniqueFieldPositions or else it won't actually move. There is also the fact that Fields are not part of the visual tree so an ElementName binding won't work. You'd have to use a {RelativeSource Self} binding and then use a path like this: "Owner.DataPresenter.FieldLayouts[0].Fields[0].ActualPosition.Column".
I modified your sample to handle the situation where you drag a column header to the right a number of spaces. I basically just iterate over the columns that overlap and shift them to the left until no more columns overlap. This isn't needed when dragging columns to the left since the EnsureUniqueFieldPositions method will handle any overlap in that scenario.
Let me know if you have any questions.
Thinking about this further, what I actually want to do is simply bind the Far column to the Near and keep the row static.
<igDp:XamDataGrid.FieldLayouts> <igDp:FieldLayout> <igDp:FieldLayout.Fields> <!-- Sort fields --> <igDp:Field Name="NearSubRootId" Label="Near Sub-root ID" Width="84" Column="0" Row="0" /> <igDp:Field Name="FarSubRootId" Label="Far Sub-root ID" Width="56" IsTabStop="False" Column="{Binding ElementName=NearSubRootId, Path=Column}" Row="1" /> <igDp:Field Name="NearRef" Label="Near ref" Width="87" Column="1" Row="0"/> <igDp:Field Name="FarRef" Label="Far ref" Width="87" Column="{Binding ElementName=NearRef, Path=Column}" Row="1"/> <igDp:Field Name="NearName" Label="Near Name" Width="70" Column="2" Row="0"/> <igDp:Field Name="FarName" Label="Far Name" Width="70" Column="{Binding ElementName=NearName, Path=Column}" Row="1"/> <igDp:Field Name="NearAmount1" Label="Near Amount1" Width="74" Column="3" Row="0"/> <igDp:Field Name="FarAmount1" Label="Far Amount1" Width="74" Column="{Binding ElementName=NearAmount1, Path=Column}" Row="1"/> <igDp:Field Name="NearCurrency1" Label="Near CCY 1" Width="74" Column="4" Row="0"/> <igDp:Field Name="FarCurrency1" Label="Far CCY 1" Width="74" Column="{Binding ElementName=NearCurrency1, Path=Column}" Row="1"/> </igDp:FieldLayout.Fields> </igDp:FieldLayout> </igDp:XamDataGrid.FieldLayouts>