TreeListView Column Freeze

Grids for WPF Forum

Posted 2 years ago by Joey Lu
Version: 22.1.3

Can I freeze the TreeListView Column just like ThemedDataGrid do? If can, how do I accomplish that?

<Style x:Key="PinButtonStyle" TargetType="Button" BasedOn="{StaticResource {x:Static themes:SharedResourceKeys.EmbeddedButtonBaseOverrideStyleKey}}">
			<Setter Property="Padding" Value="1" />
			<Setter Property="ContentTemplate" Value="{DynamicResource {x:Static themes:SharedResourceKeys.UnpinGlyphTemplateKey}}" />

				<DataTrigger Binding="{Binding Path=Column.IsFrozen, RelativeSource={RelativeSource AncestorType={x:Type DataGridColumnHeader}}}" Value="False">
					<Setter Property="ContentTemplate" Value="{DynamicResource {x:Static themes:SharedResourceKeys.PinGlyphTemplateKey}}" />

		<!-- Header template for columns that includes the "pin" button  -->
		<DataTemplate x:Key="ColumnHeaderTemplate">
				<Button DockPanel.Dock="Right" Style="{StaticResource PinButtonStyle}" Margin="3,0,0,0" VerticalAlignment="Center"
						Command="{x:Static datagrid:DataGridCommands.ToggleFrozenColumn}"
						CommandParameter="{Binding Path=., RelativeSource={RelativeSource AncestorType={x:Type DataGridColumnHeader}}}" />
				<TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis" />

<datagrid:ThemedDataGrid x:Name="datagrid" AutoGenerateColumns="False" CanUserAddRows="False"
				CanUserDeleteRows="False" ItemsSource="{Binding Source={x:Static sampleCommon:SampleData.Values}}"
				SelectionUnit="FullRow" GridLinesVisibility="All" FrozenColumnCount="1"
				CellStyle="{StaticResource DataGridCellStyleKey}">
				<datagrideditors:DataGridInt32Column Binding="{Binding Integer}" Header="Integer"
						HeaderTemplate="{StaticResource ColumnHeaderTemplate}" />
				<DataGridTextColumn Binding="{Binding String}" Header="String"
						HeaderTemplate="{StaticResource ColumnHeaderTemplate}" />
				<datagrideditors:DataGridDateColumn Binding="{Binding DateTime}" Header="Date" 
						HeaderTemplate="{StaticResource ColumnHeaderTemplate}" />
				<DataGridCheckBoxColumn Binding="{Binding Boolean}" Header="Boolean"
						HeaderTemplate="{StaticResource ColumnHeaderTemplate}" />
				<DataGridTextColumn Binding="{Binding LongString}" Header="Long String" />

Codes from  SampleBrowser/ProductSamples/DataGridSamples/QuickStart/FrozenColumns

[Modified 2 years ago]

Comments (1)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA


The TreeListView control currently has a FrozenColumnCount property that you set to the number of columns at the start to be frozen.  It doesn't have that specific behavior where any arbitrary column header can be clicked and will be moved to the front of the column list when frozen.

You could probably achieve something like that though if you make a custom command that moves the column around based on if it's freezing or unfreezing.  Here is our source for that behavior in ThemedDataGrid.  Our TreeListViewColumn.Index property is similar to their ColumnIndex property, but ours can't be set.  You would have to modify the Columns collection of the owner TreeListView control instead to alter the index.  Then also change FrozenColumnCount appropriately after.

Actipro Software Support

The latest build of this product (v24.1.2) was released 28 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.