C1.wpf.datagrid reorder column programmatically

Posted by: christoph.schattka on 20 April 2023, 11:14 pm EST

  • Posted 20 April 2023, 11:14 pm EST

    Hello,

    I’m using an old componentone C1Datagrid for WPF Version 3.0.20093.100.

    As example:

    grid:C1DataGrid x:Name=“DG_Lade_Aufträge” HorizontalScrollbarPlacement=“Bottom” AllowEdit=“True” BorderThickness=“2” BorderBrush=“#FF00A0F5” HeaderCellContentTemplate=“{StaticResource Grid_CLFont}” ItemCellShowContentTemplate=“{StaticResource Grid_OLFont}” ScrollViewer.HorizontalScrollBarVisibility=“Visible” HorizontalAlignment=“Left” Height=“Auto” Margin=“0,0,0,0” VerticalAlignment=“Top” Theme=“{DynamicResource {c1grid:C1ThemeKey ThemeName=MediaPlayer, TypeInTargetAssembly={x:Type c1grid:C1DataGrid}}}” GroupByCaption=“” GroupByVisibility=“Collapsed” AllowHierarchicalData=“False” AllowHorizontalSplit=“False” AllowHorizontalColumnSizing=“True” AllowVerticalSplit=“False” AllowVerticalSplitSizing=“False” SyncItemCellWidthToHeader=“True” AllowColumnMove=“False” AllowDelete=“False” HorizontalContentAlignment=“Center” VerticalContentAlignment=“Center” ForceCursor=“False” Foreground=“Silver” Width=“Auto” HeaderCellTextAlignment=“Center” NewRowPlacement=“None”>

    c1grid:C1DataGrid.Columns

    <c1grid:Column ReadOnly=“True” PropertyName=“Auftrag” ColumnName=“Auftrag” HeaderCellWidth=“135” HeaderCellContentTemplate=“{StaticResource Grid_CLFont}” ItemCellShowContentTemplate=“{StaticResource Grid_OLFont}” />

    <c1grid:Column ReadOnly=“True” PropertyName=“Vorgang” ColumnName=“Vorgang” HeaderCellWidth=“140” HeaderCellContentTemplate=“{StaticResource Grid_CLFont}” ItemCellShowContentTemplate=“{StaticResource Grid_OLFont}” />

    <c1grid:Column ReadOnly=“True” PropertyName=“Status” ColumnName=“Status” HeaderCellWidth=“120” HeaderCellContentTemplate=“{StaticResource Grid_CLFont}”>

    c1grid:Column.ItemCellShowContentTemplate





    <TextBlock.Style>



    <Style.Triggers>













































    </Style.Triggers>



    </TextBlock.Style>





    </c1grid:Column.ItemCellShowContentTemplate>

    </c1grid:Column>

    The first column is “Auftrag”, second one “Vorgang” and so on. During runtime the quantity and the Index of Column depends of a result from a sql query.

    That means actual first column should be the the fifth column after sql execute.

    My question now: is there a posibility to change the position(index) of the Column by program like this:

    if column.name = “Auftrag” then column(“Auftrag”).Index = 5

    Many thanks for your help.

    Best regards,

    Chris

  • Posted 24 April 2023, 5:45 am EST

    Hi Chris,

    You can change the index of the datagrid column via code-behind as shown in the following line of code:

    datagrid.ActualColumns.Move(1, 3);  // Move(old_index, new_index)

    As per the results of your SQL query you can change the parameters passed to Datagrid.ActualColumns’ Move() method.

    We have attached a sample application for your reference. Please check reorderCol.zip

    In case your requirement differs from our understanding, please let us know.

    Thanks & Regards,

    Aastha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels