Current filter:
                                You should refresh the page.
                                  • Hi Team
                                    How can I implement a logic in a value converter class descendant, both, ConvertToStorageType and ConvertFromStorageType methods where i can get the current object Oid and the name of the current column which i am changing. So, i can use them to perform aditional task before and after i apply some conversion type.
                                    Is it that posible? , i would appreciate any suggestion.

                                1 Solution

                                Creation Date Importance Sort by

                                Hi Pedro,

                                Value Converters have no context. There is no way to obtain an object key or property name in the ConvertToStrorageType and ConvertFromStorageType methods. You can use non-persistent calculated properties to achieve the same result.

                                private string fPersistentProperty; [MemberDesignTimeVisible(false)] public string PersistentProperty { get { return fPersistentProperty; } set { SetPropertyValue(nameof(PersistentProperty), ref fPersistentProperty, value); } } [NonPersistent] public CustomType NonPersistentProperty { get { return CalculateNonPersistentProperty(); } set { UpdateNonPersistentProperty(value); } }
                                Show all comments
                                • Pedro Martinez 2 09.22.2019

                                  Hi Uriah

                                  Thanks for your answer.

                                  I am wondering if your suggestion can be used in my case, what i need is to convert decimal to string, however i need to encrytp/decrypt that string, i am using a custom class descendant of value converter and applying encrypting logical at ConvertFromStorageType and ConvertToStorageType Method, its works already fine, however i need to apply additional logical with column Name and OID of the current object.

                                  Do you think the PersistentAlias attribute can help?


                                • Anatol (DevExpress Support) 09.23.2019

                                  Hello Pedro,

                                  Please note that, in addition to the aforementioned limitation, we do not recommend that you use value converters for encryption. Here is the corresponding node from our documentation:

                                  The value converter mechanism is designed to allow persisting non-persistent data types by transforming them into a persistable equivalent. Value converters are not intended for introducing encryption, compression, or other business logic into the persistence process.

                                  The solution suggested by Uriah can be used to store an encrypted string. In his example, the value should be encrypted and decrypted in the CalculateNonPersistentProperty and UpdateNonPersistentProperty methods. You can implement them similarly to your ConvertFromStorageType and ConvertToStorageType methods.
                                  Please do not hesitate to contact us if you need further assistance.

                                • Pedro Martinez 2 09.24.2019

                                  Hi Anatol

                                  Thanks for your answer

                                  I have implemented Uriah's suggestoin, it works fine, however I still having some doubts.

                                  In the example there is a non-persistent property with Get, however, when I input its value, the objects seems still without change, so, Save actions its no requiered, you can leave that records and even lost it value, so, a little confuse for user, however the value is passed and stored to the persistent property. Please see my attached video about.

                                  At get and set of non-persistent property , i am converting the value and passing it to the persistent property.

                                  Here is my code.

                                  [Size(SizeAttribute.DefaultStringMappingFieldSize)] [Browsable(false)] [ModelDefault("Caption", "Hide Value")] [Appearance("Deshabilitar Salario Str - Cargo", Enabled = false)] public string SalarioStr { get { return _salarioStr; } set { SetPropertyValue("SalarioStr", ref _salarioStr, value); } } [ModelDefault("Caption", "Showed Value")] [NonPersistent] public decimal SalarioUsr { get { if (_salarioStr != null) { byte[] encrypted = ConvertValues.ToByteArray(_salarioStr); // Decrypt the bytes to a string. string roundtrip = ConvertValues.DecryptStringFromBytes(encrypted); _salarioUsr = Convert.ToDecimal(roundtrip); } return _salarioUsr; } set { // Encrypt the string to an array of bytes. byte[] encrypted = ConvertValues.EncryptStringToBytes(Convert.ToString((decimal)(value))); _salarioStr = ConvertValues.FromArrayToString(encrypted); SetPropertyValue("SalarioUsr", ref _salarioUsr, value); } }

                                  Seems to me, I can implement this solutions but no with properties input by user, just passing its values in code instead.

                                  Sorry, if i am missunderstanding your idea.

                                • Gosha (DevExpress Support) 09.25.2019

                                  Hi Pedro,

                                  The SetPropertyValue method raises the INotifyPropertyChanged.PropertyChanged event to notify data-aware components about changes. But, it's raised only if a new value does not equal an old value. According to your logic, the _salarioUsr field already has the new value when the SetPropertyValue method is called. As a result, the INotifyPropertyChanged.PropertyChanged event is not raised. For your scenario, it's just sufficient to set a value to the SalarioStr property rather than to the _salarioStr field.

                                  byte[] encrypted = ConvertValues.EncryptStringToBytes(Convert.ToString((decimal)(value))); SalarioStr = ConvertValues.FromArrayToString(encrypted);
                                • Pedro Martinez 2 09.25.2019

                                  Thanks Gosha

                                  Your solution works as expected, i am ready to complete my original task.

                                  Thanks so much to all for help.


                                • Gosha (DevExpress Support) 09.25.2019

                                  You are welcome, Pedro!