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
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 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
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
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
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
Thanks for the quick response. It works.
Regards,
Laks
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
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
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
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