PropertyGrid - How to show string property as password property?

9 posts, 1 answers
  1. Laksmono
    Laksmono avatar
    5 posts
    Member since:
    Jul 2012

    Posted 19 Jul 2012 Link to this post

    Hi,

    Anyone know how to display string as password in RadPropertyGrid?
    I've tried to use the PasswordPropertText attribute as the original PropertyGrid, but it is not working.

    [PasswordPropertyText(true)]
    public string Password  {get;set;}

    I hope that telerik still maintain the original behaviour, to keep the control's usage intuitive.

    Regards,
    Laks
  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 20 Jul 2012 Link to this post

    Hi Laksmono,

    Thank you for writing.

    Currently, RadPropertyGrid does not support this attribute. You can achieve the same result through the EditorInitialized event. Here is an example hot to do this:
    private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
    {
      if (((PropertyGridItem)e.Item).Name == "PasswordProperty")
      {
        BaseTextBoxEditorElement element = ((PropertyGridTextBoxEditor)e.Editor).EditorElement as BaseTextBoxEditorElement;
        element.PasswordChar = '*';
      }
    }
    I have logged a feature request into our Public Issue Tracking System - PITS for this attribute and we will add it to the list of supported attributes in one of our next releases. You can track the progress of the feature and add your vote/comment to it on the following link - PITS Feature. 

    I have also updated your Telerik points for the suggestion.

    I hope this will be useful. Should you have further questions, I would be glad to help.
     
    Kind regards,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Michael
    Michael avatar
    14 posts
    Member since:
    Jun 2012

    Posted 19 Aug 2012 Link to this post

    Second the motion. a PasswordTextBoxEditor and/or Element would be awesome. That would reduce the code we've got chasing PasswordChar all over creation significantly. As far as I know this only applies when we're using a RadPropertyStore, which is just about always, or until better support comes along for attributed adapted domain object properties: i.e. using the PasswordPropertyTextAttribute.
  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 22 Aug 2012 Link to this post

    Hi guys,

    I am happy to inform you that this attribute is now supported in RadPropertyGrid. You can apply it to a property in a class or add it to the attributes collection of a PropertyStoreItem and it will be respected.

    I hope this will be useful. Feel free to write back with any further inquiries.

    Regards,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  6. Laksmono
    Laksmono avatar
    5 posts
    Member since:
    Jul 2012

    Posted 07 Sep 2012 Link to this post

    Hi Ivan,

    Thank you for following this. Could you please confirm in which version this feature will be available? when you said it is now supported, does it mean 2012.2.726.40?

    When will the Q3 2012 be available?

    Your previous workaround by using the EditorInitialized event, does not work. As it is Editor Initialized, the password char only applied to the Control that was rendered during editing. When leaving the edit mode, the password is visible again.

    Regards,
    Laks
  7. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 10 Sep 2012 Link to this post

    Hi Laksmono,

    Thank you for writing back.

    Please, accept my apologies for misleading you with my previous post. The feature is indeed implemented but will be available in our next release which is Q3 2012. The release should be out by the end of October.

    On the workaround, if you want to have the password characters displayed when the property is not in edit mode you have to use the ItemFormatting event. Here is a sample code:
    private void radPropertyGrid1_ItemFormatting(object sender, PropertyGridItemFormattingEventArgs e)
    {
      PropertyGridItem item = e.Item as PropertyGridItem;
     
      if (item != null && item.Name == "Password")
      {
        StringBuilder text = new StringBuilder();
     
        if (!string.IsNullOrEmpty(item.FormattedValue))
        {
          for (int i = 0; i < item.FormattedValue.Length; i++)
          {
            text.Append('*');
          }
        }
     
        ((PropertyGridItemElement)e.VisualElement).ValueElement.Text = text.ToString();
      }
    }

    I hope this will help. If you need further assistance, feel free to write back.
     
    Greetings,
    Ivan Petrov
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  8. Laksmono
    Laksmono avatar
    5 posts
    Member since:
    Jul 2012

    Posted 10 Sep 2012 Link to this post

    Hi Ivan,

    Thanks for the quick response. It works.

    Regards,
    Laks
  9. Laksmono
    Laksmono avatar
    5 posts
    Member since:
    Jul 2012

    Posted 31 Jan 2013 Link to this post

    Hi Ivan,

    I could not find a way to report Bug in PITS, what I found is just adding suggestion for new feature. So I will just write here,

    I have found a bug in the implementation of the PasswordPropertyText Attribute in Q3 2012. The textbox editor does change into asterisk, but once we move to other string property which does not have PasswordPropertyText Attribute, it will still display the text as asterisk.

    This apply to all text box editor. I understand that Telerik might use single instance of editor for the same type of editor for performance reason. But for this I think it is better to use different instance of TextBox editor or else resetting the item formatting every time the user select the other string property which is not password.

    Regards,
    Laks
  10. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 04 Feb 2013 Link to this post

    Hello Laksmono,

    Thank you for your follow up.

    Indeed, we cache editors so we can improve the performance. Nevertheless, this is an issue and I have logged it in our PITS. You can track its progress and add votes or comments to it on the following link - PITS Issue. We will do our best to fix this issue for our upcoming release Q1 2013.

    I have updated your Telerik points for bringing this issue to our attention.

    Feel free to write back with any further questions.

    Greetings,
    Ivan Petrov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top
UI for WinForms is Visual Studio 2017 Ready