Question

So I have a simple window which contains only a XamDataGrid that holds preview data of a dynamic query generated at run-time...

public partial class DataPreview : Window
{
    public DataTable Data { get; set; }
    public DataPreview(string SQL)
    {
        InitializeComponent();

        this.DataContext = this;
        Data = DatabaseManager.ExecuteQuery(SQL);
    }
}

I have databound to the datasource of the XamDataGrid...

<igDP:XamDataGrid DataSource="{Binding Data}" ScrollingMode="Immediate">
     <igDP:XamDataGrid.FieldSettings>
          <igDP:FieldSettings
             AllowEdit="False"/>
     </igDP:XamDataGrid.FieldSettings>
</igDP:XamDataGrid>

Now this all works fine, the problem is the datatype of the editor in the XamDataGrid does not match the datatype of the field sometimes. For example all numerics show with a dollar sign. I tried to add this line...

EditAsType="{x:Type sys:String}"

Which fixed everything except actual currency amounts, which now display as xx.xxxx with no dollar sign. All the solutions I have found online seem to edit the field's directly in the xaml, but since the fields are all dynamic this is not an option. Is there something I can do to set the editors correctly in the xaml? Or some routine I can do in the code to massage the data into displaying correctly from the XamDataGrid? Can anyone share any code using XamDataGrid in a related way with all dynamic columns, but able to format them correctly based on datatype?

Was it helpful?

Solution

The editor that is used for a field of a specific type can be set using the ValueEditor.RegisterDefaultEditorForType. If the editor is the correct type and you are looking to change the mask for a given type then you could use the XamMaskedEditor.RegisterDefaultMaskForType.

If you are looking to set the mask or the editor differently for different fields of the same type, then you would need to do this in code after the FieldLayout has been created. For this you could use the FieldLayoutInitialized event.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top