Ticket T1098901
Visible to All Users

TokenEdit - MaskBox internal property is null when WXI or WXI Compact skin is applied

created 3 years ago

Hello,

To reproduce the error do the following:

1- Select the skin WXI or WXI Compact
2- Open the Form which contains the TokenEdit assigning the data.
3- Upon reaching the line where the property is configured, the exception error will be thrown.

C#
class Data { public int Id { get; set; } public string Description { get; set; } } List<Data> myList = new List<Data> { new Data { Id = 1, Descripcion = "SomeData1" }, new Data { Id = 21, Descripcion = "SomeData2" }, //.... }; tokenEdit1.Properties.DisplayMember = "Description"; tokenEdit1.Properties.ValueMember = "Id"; tokenEdit1.Properties.DataSource = myList; tokenEdit1.MaskBox.Enabled = false; ///ERROR HERE

NullReferenceException:

C#
System.NullReferenceException: 'Object reference not set to an instance of an object.'

If you use any other skin it will work correctly, now do it the other way around:

1- Apply any other skin example: The Bezier.
2- Open the form and the property will be applied correctly.
3- Then apply the WXI or WXI Compact skin, the error will NOT occur, but the previous configuration of the MaskBok will not work and will allow entering text.

In the meantime to avoid the error, I validate that the property is not null before applying it, although this does not solve the problem of still allowing the user to enter text.

Code
if (tokenEdit1.MaskBox != null) tokenEdit1.MaskBox.Enabled = false;

Please check if this also happens on your side.

Thank you…

Answers approved by DevExpress Support

created 3 years ago

Hello,

Thank you for the code snippet.

The MaskBox property is an internal text editor used in our editors which is derived from the standard TextBox. When your application uses the WXI skin, all editors are switched to advanced mode. An editor that is in advanced mode no longer uses MaskBox for text input. Instead, it uses an internal editor fully implemented by our team. The MaskBox property is null when an editor is in advanced mode, which is the case when your application uses the WXI skin.

I hope you will find this information useful. Should you have additional question, let me know.

    Show previous comments (3)

      Hi @Christian Santos, thanks…

      @Stas

      Thanks, I tried your solution, when the TokenEdit does NOT contain any added token, it still allows text to be written, although obviously when the object loses focus, the text is automatically deleted, therefore the solution you indicated works only after adding the first Token, but the idea is not to allow entering any text, that is, initially my TokenEdit only has the data source assigned but does not have Aggregate Tokens, the Tokens are added by code depending on some actions that the user performs on the screen.

      It only works if the TokenEdit contains at least 1 added token, when it does not contain it allows entering text…

      In case there is no other solution, I will leave it this way.

      Thank you…

      DevExpress Support Team 3 years ago

        I ran some additional tests and, indeed, this solution can be limiting.
        I researched our source code and found another way to implement this task and it seems to work exactly as you require.
        The idea is to create a new custom TokenEdit (see Custom Editors) and override its ActivateTextEditor:

        C#
        public class CustomTokenEdit : TokenEdit { public override void ActivateTextEditor() { //base.ActivateTextEditor(); } }

        I created a sample project for your reference. Please test it and let me know if this solution meets your requirements.

          Hello Stas, I hope you are well.

          I apologize for the late response, I was out of the office on vacation.

          I have tried the sample you provided and it works fine, this is the expected result.

          Thank you…
          Have a nice day!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.