This is a migrated thread and some comments may be shown as answers.

PropertyGrid - How to show string property as password property?

12 Answers 871 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Laksmono
Top achievements
Rank 1
Laksmono asked on 20 Jul 2012, 03:57 AM
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

12 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 20 Jul 2012, 12:43 PM
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 >>
0
Michael
Top achievements
Rank 1
answered on 19 Aug 2012, 03:26 PM
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.
0
Ivan Petrov
Telerik team
answered on 22 Aug 2012, 03:29 PM
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 >>
0
Laksmono
Top achievements
Rank 1
answered on 07 Sep 2012, 09:00 AM
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
0
Ivan Petrov
Telerik team
answered on 10 Sep 2012, 01:46 PM
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 >>
0
Laksmono
Top achievements
Rank 1
answered on 11 Sep 2012, 03:14 AM
Hi Ivan,

Thanks for the quick response. It works.

Regards,
Laks
0
Laksmono
Top achievements
Rank 1
answered on 31 Jan 2013, 07:31 AM
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
0
Accepted
Ivan Petrov
Telerik team
answered on 04 Feb 2013, 05:20 PM
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.
0
Shashi
Top achievements
Rank 1
answered on 03 Feb 2020, 12:49 PM
But once after leaving the focus, normal text gets displayed with this.
0
Nadya | Tech Support Engineer
Telerik team
answered on 03 Feb 2020, 04:11 PM

Hello Shashi,

According to the provided brief information, I suppose that you use the provided approach in this forum thread in order to display an object's text like a password. If you do so, could you please confirm that you use the suggested ItemFormatting event as well as the EditorInitialized event. I would like to note that the EditorInitialized event is used to set a special mask character while typing in the text box and you are in edit mode. On the other hand, if you want to have the password characters displayed when the property is not in edit mode you have to use the ItemFormatting event. I tested the provided solution and it works as expected on my end. You can use these two events together in order to display only a special character at any time.

However, this forum thread is quite old since 2012. RadPropertyGrid now offers PasswordPropertyTextAttribute which is suitable for your scenario. Feel free to use it in order to benefit from the new improvements of the control. 

Please let me know if there is anything else I can help you with. 

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Shashi
Top achievements
Rank 1
answered on 04 Feb 2020, 07:24 AM
Using Item formatting event, i could get input masked even in non editing mode. But, i could see that masking only when i click on that field, else it is showing empty. Can i do something so that even if i don't click on that element i should be able to see the masked input?
0
Nadya | Tech Support Engineer
Telerik team
answered on 04 Feb 2020, 08:10 PM

Hello Shashi,

Following the provided brief information it is not clear what is your real set-up. I attached my sample project to this thread. As you can see in the attached GIF file only asterisks are visible.

Could you please refer to the project and let me know how it differs from yours? It will be greatly appreciated if you can specify the exact steps that you follow in order to replicate the behavior on my end. Thus, we will be able to assist you further. 

I am looking forward to your reply.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PropertyGrid
Asked by
Laksmono
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Michael
Top achievements
Rank 1
Laksmono
Top achievements
Rank 1
Shashi
Top achievements
Rank 1
Nadya | Tech Support Engineer
Telerik team
Share this question
or