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
3220
xamDataGrid NumericField. Get rid of the PromptChar
posted

Hello,

I would like to get rid of the PromptChar in the NumericField. When using ' ', it is not visible but when I click in the cell, you can see that the spaces are highlighed. I am adding these fields in Code Behinde.

When using .PromptChar = null, the default char _ is used. Is there any way to hide the promptchar at all?

Here is my Code:

string fieldName = infeedConfig.InfeedConfigId.ToString();
                    string fieldLabel = string.Format("{0} [{1}]", infeedConfig.DisplayName, infeedConfig.DisplayUOM);

                    Infragistics.Windows.DataPresenter.NumericField fieldAdd = new Infragistics.Windows.DataPresenter.NumericField();
                    fieldAdd.Name = fieldName;
                    fieldAdd.Label = fieldLabel;
                    fieldAdd.PromptChar = ' ';
                    fieldAdd.TrimFractionalZeros = true;
                    fieldAdd.Format = "0.###";
                    fieldAdd.SpinButtonDisplayMode = Infragistics.Windows.Editors.SpinButtonDisplayMode.Always;
                    fieldAdd.SpinIncrement = 1;                    
                    _infeedValuesFields.Add(fieldAdd);
                    grdInfeed.FieldLayouts[0].Fields.Add(fieldAdd);         

In XAML I can use the following code as workaround to hide it at all:

<igWPF:NumericField Name="COL_Minor" Width="100" Format="0.##" Label="{x:Static l:lang.DefectGroupStatisticSettings_Group_Minor}">
                                    <igWPF:NumericField.PromptChar>
                                        <sys:Char></sys:Char>
                                    </igWPF:NumericField.PromptChar>
                                </igWPF:NumericField>

  • 2700
    Offline posted
    Hello Bin,

     

    I have been looking into you question and after investigation determined that your requirement may be achievable, however, not through code-behind, actually. Moreover, I found this forum thread where your question was already answered.

     

    To demonstrate what I am talking about, I have attached two sample applications consisting of a XamDataGrid, whose “Price” field is configured as per the code-snippet provided by you.

     

    In the first sample – “XNEPromptCharHidden” I managed to achieve your requirement, by specifying the EditorStyle of the “Price” NumericField with a style, targeting the XamNumericEditor type and setting the prompt character as “” on it, rather on the NumericField object itself:

     

    <igWPF:NumericField Name="Price"
                                                TrimFractionalZeros="True"
                                                SpinButtonDisplayMode="Always"
                                                SpinIncrement="1"
                                                Format="0.###">
                                <igWPF:NumericField.Settings>
                                    <igWPF:FieldSettings EditAsType="{x:Type sys:Double}">
                                        <igWPF:FieldSettings.EditorStyle>
                                            <Style TargetType="{x:Type igWPF:XamNumericEditor}">
                                                <Setter Property="PromptChar"
                                                        Value="" />
                                            </Style>
                                        </igWPF:FieldSettings.EditorStyle>
                                    </igWPF:FieldSettings>
                                </igWPF:NumericField.Settings>
                            </igWPF:NumericField>

     

    As you can see in the image below, the selection in the cell does not involve the empty prompt characters and we are able to type more:

     


    In the second sample “XNEPromptChar”, I tried to recreate the same, this time creating the FieldLayout through code, as you mentioned this is your approach. The above solution could be recreated in code, particulary the style. There are also two approaches to assigning the EditorStyle: 1) entirely programmatically:

     

    NumericField mileageField = new NumericField();
                priceField.Name = "Mileage";
                priceField.TrimFractionalZeros = true;
                priceField.SpinButtonDisplayMode = SpinButtonDisplayMode.Always;
                priceField.SpinIncrement = 1;
                priceField.Format = "0.###";
                Style numericEditorStyle = new Style(typeof(XamNumericEditor));
                numericEditorStyle.Setters.Add(new Setter(XamNumericEditor.PromptCharProperty, ""));
                FieldSettings pfFieldSettings = new FieldSettings();
                pfFieldSettings.EditAsType = typeof(Double);
                // First option - assign the programmatically created style
                pfFieldSettings.EditorStyle = numericEditorStyle;

     

    and 2) Have the style defined in xaml with a Key and assign it in code:

     

    // Second option - style is defined in xaml, in the grid's resouces, assign it here
    pfFieldSettings.EditorStyle = this.xdg1.Resources["XNEStyle"] as Style;

     

    For some reason, though, the empty prompt character seems to be defaulted to null, when the style is assigned through code. As you already know, when the PromptChar is set to null, it reverts to the default “_”. The same happens if we assign ‘\0’ or (char)0 as the prompt char.

     

    In conclusion, if you would like your field editor to look like it does not have a prompt char, you could consider defining your fields in xaml, like in the “XNEPromptCharHidden” sample. Apart from that, completely disabling the prompt char is not currently achievable in code.

     

    You can find the samples attached below. Please, test both of them on your side and in case of any other questions, please, let me know.

     

    Sincerely,
    Bozhidara Pachilova
    Associate Software Developer