Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
How to format a column
posted

I've read several threads but I haven't been able to figure it out.  I'm trying to right align specific columns and format them to N2.  I have to do this in code (vb) because the columns that I will be formatting are dynamically generated. I'm binding the grid to a datatable view.

How do I do this?

-Thanks!

Parents
No Data
Reply
  • 28464
    Verified Answer
    posted

    Hello,

    With code you can hook the FieldLayoutInitialized event and create custom styles for the presenter and editor of the Field in the event, e.g.

    <igDP:XamDataGrid x:Name="XamDataGrid1" DataSource="{Binding Source={StaticResource BookData},XPath=Book}" FieldLayoutInitialized="XamDataGrid1_FieldLayoutInitialized">                                            
                </igDP:XamDataGrid>

     C#

            private void XamDataGrid1_FieldLayoutInitialized(object sender, Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs e)
            {
               
                Style cvp = new Style();
                cvp.TargetType = typeof(CellValuePresenter);
                cvp.Setters.Add(new Setter(CellValuePresenter.HorizontalContentAlignmentProperty, HorizontalAlignment.Right ));                   
               
                Style es = new Style();
                es.TargetType = typeof(XamTextEditor);
                es.Setters.Add(new Setter(XamTextEditor.FormatProperty, "N2"));

                e.FieldLayout.Fields[0].Settings.CellValuePresenterStyle = cvp;
                e.FieldLayout.Fields[0].Settings.EditorStyle = es;           
               
            }

    VB.NET

    Private Sub XamDataGrid1_FieldLayoutInitialized(sender As Object, e As Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs)

        Dim cvp As New Style()
        cvp.TargetType = GetType(CellValuePresenter)
        cvp.Setters.Add(New Setter(CellValuePresenter.HorizontalContentAlignmentProperty, HorizontalAlignment.Right))

        Dim es As New Style()
        es.TargetType = GetType(XamTextEditor)
        es.Setters.Add(New Setter(XamTextEditor.FormatProperty, "N2"))

        e.FieldLayout.Fields(0).Settings.CellValuePresenterStyle = cvp
        e.FieldLayout.Fields(0).Settings.EditorStyle = es

    End Sub

    More info can be found in the following forum thread:

    http://forums.infragistics.com/forums/p/2187/14781.aspx#14781

Children