Home Forums WPF controls Xceed DataGrid for WPF individual column alignment

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #24687 |

    Hi,

    i am new to this control looking for a way to set the column alignment individual for each column by code in vb. The columns a added like this:

    f_Col = New Xceed.Wpf.DataGrid.Column
    With f_Col
    .FieldName = “KDBEZ” : .Title = “Name” : .Width = 150
    End With
    Me.myGrid.Columns.Add(f_Col)

    In the forum i found a ColumnManagerRow that can do the horizontal and vertical content alignment, but how to access the ColumnManagerRow from vb code? I tried:

    Dim cmr As Xceed.Wpf.DataGrid.ColumnManagerRow = CType(Me.OrdersGrid.View.FixedHeaders.Item(1), Xceed.Wpf.DataGrid.ColumnManagerRow)

    but that does not work … please help …

    Thanks martin

    Imported from legacy forums. Posted by Martin (had 1063 views)

    Xceed Support
    Member
    Post count: 5658

    What you will need to do is provide a new DataTemplate that sets the alignment properties (HorizontalAlignment and VeritcalAlignment) to each column’s CellContentTemplate property.

    In code, you will need to use the <a href=”http://msdn2.microsoft.com/en-us/library/system.windows.frameworkelementfactory.aspx”>FrameworkElementFactory</a&gt; class; however, this class has been deprecated and it is highly recommended to manipulate templates in <a href=”http://msdn2.microsoft.com/en-us/library/ms742521.aspx”>XAML</a&gt;.

    If you would like an example specific to Xceed DatagGrid for WPF, you can refer to <a href=”http://doc.xceedsoft.com/products/XceedWpfDataGrid/Templates.html”>Templates</a&gt; page in the documentation. Notably, example 1.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 624 views)

    User (Old forums)
    Member
    Post count: 23064

    It would be nice if Alignment exists at Column level and Cell would inherit the property from Column by default.

    Imported from legacy forums. Posted by nat (had 1764 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Jenny,

    thanks for your reply, here is my solution. Maybe this is helping someone:

    defining datatemplates in grid.resources section

    <DataTemplate x:Key=”Column_CellContent_AlignLeft”>
    <TextBlock Text=”{Binding Path=.}” Block.TextAlignment=”Left” />
    </DataTemplate>
    <DataTemplate x:Key=”Column_CellContent_AlignCenter”>
    <TextBlock Text=”{Binding Path=.}” Block.TextAlignment=”Center” />
    </DataTemplate>
    <DataTemplate x:Key=”Column_CellContent_AlignRight”>
    <TextBlock Text=”{Binding Path=.}” Block.TextAlignment=”Right” />
    </DataTemplate>

    set the Column.CellContentTemplate to the data template:

    <xcdg:DataGridControl.Columns>

    <xcdg:Column FieldName=”F1″ Title=”F1″ Width=”50″ ReadOnly=”True”
    xcdg:Column.CellContentTemplate=”{StaticResource Column_CellContent_AlignCenter}” />

    <xcdg:Column FieldName=”F2″ Title=”F2″ Width=”150″ xcdg:Column.CellContentTemplate=”{StaticResource Column_CellContent_AlignLeft}” />

    <xcdg:Column FieldName=”F3″ Title=”F3″ Width=”100″ xcdg:Column.CellContentTemplate=”{StaticResource Column_CellContent_AlignRight}” />

    </xcdg:DataGridControl.Columns>

    define Colums and set Column.CellContentTemplate by code:

    f_Col = New Xceed.Wpf.DataGrid.Column
    With f_Col
    .FieldName = “F1” : .Title = “F1” : .Width = 150
    .CellContentTemplate = Me.myGrid.Resources.Item(“Column_CellContent_AlignRight”)
    End With
    Me.myGrid.Columns.Add(f_Col)

    bye martin

    Imported from legacy forums. Posted by Martin (had 4351 views)

    User (Old forums)
    Member
    Post count: 23064

    Awesome, thanks for your post.

    Imported from legacy forums. Posted by Giuliano (had 969 views)

    User (Old forums)
    Member
    Post count: 23064

    OMG, I miss the days when setting the alignment was as easy as grid.columns(0).align = “right”

     

    Imported from legacy forums. Posted by Eduardo (had 946 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.