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!
Thanks for the code, it works great. I read the other thread and I'm just not quite getting it. This WPF stuff is, for some reason, harder to wrap my mind around.
I suspect this isn't the best way to do this but i passed a list of column names that I want formatted and iterate through each grid column and format if it is in the list.
Private Sub XamDataGrid1_FieldLayoutInitialized(ByVal sender As Object, ByVal e As Infragistics.Windows.DataPresenter.Events.FieldLayoutInitializedEventArgs) Handles XamDataGrid1.FieldLayoutInitialized Dim cvp As New Style() cvp.TargetType = GetType(CellValuePresenter) cvp.Setters.Add(New Setter(CellValuePresenter.HorizontalContentAlignmentProperty, HorizontalAlignment.Right)) cvp.Setters.Add(New Setter(CellValuePresenter.BorderBrushProperty, Media.Brushes.Gainsboro)) cvp.Setters.Add(New Setter(CellValuePresenter.BorderThicknessProperty, New Thickness(0, 0, 1, 1))) Dim es As New Style() es.TargetType = GetType(XamTextEditor) es.Setters.Add(New Setter(XamTextEditor.FormatProperty, "N2")) For i As Integer = 0 To e.FieldLayout.Fields.Count - 1 If _columnFormatList.Contains(e.FieldLayout.Fields(i).Name) Then e.FieldLayout.Fields(i).Settings.CellValuePresenterStyle = cvp e.FieldLayout.Fields(i).Settings.EditorStyle = es End If Next End Sub
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 = esEnd Sub
More info can be found in the following forum thread:
http://forums.infragistics.com/forums/p/2187/14781.aspx#14781