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

Is it possible to make a cell behave like Password Control

7 Answers 214 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hari M S
Top achievements
Rank 1
Hari M S asked on 06 Apr 2010, 01:42 PM
Hi

       Is it possible to make a cell in GridView Control behave like Password Control? I mean, We can change the Edit Text Box to Password Field, so that the user can't view the things he typed in, same thing acn we implment in Grid Cell?..

Waiting for a Positive Reply as well as Thanking you in advance..

Thanks
Hari

7 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 08 Apr 2010, 09:53 AM
Hi Hari M S,

You can achieve this behavior. You should obfuscate the text that is displayed in the cells when they are not in edit mode. Hence, you need to subscribe for the CellFormatting  event. You can use the following code snippet as sample:

private void radGridView_CellFormatting(object sender, CellFormattingEventArgs e)
 {
     GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
  
     if (dataColumn != null && dataColumn.UniqueName == "Password")
     {
         object value = e.CellElement.RowInfo.Cells["Password"].Value;
         string text = String.Empty;
         if (value != null)
         {
             int passwordLen = Convert.ToString(value).Length;
             text = String.Join("*", new string[passwordLen]);
         }
  
         e.CellElement.Text = text;
     }
 }

Also you need to make a text box editor to be a password box. You can do it by handling CellEditorInitialized event.

private void radGridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
  
    if (dataColumn != null && dataColumn.UniqueName == "Password")
    {
        RadTextBoxEditor textBoxEditor = this.radGridView.ActiveEditor as RadTextBoxEditor;
          
        if (textBoxEditor != null)
        {
            RadTextBoxEditorElement editorElement = textBoxEditor.EditorElement as RadTextBoxEditorElement;
            editorElement.PasswordChar = '*';
        }
    }
}

If you have further questions feel free to write us back.

Greetings,
Svett
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Jenson
Top achievements
Rank 2
answered on 08 Oct 2012, 02:52 AM
I follow the codes closely, and managed to display the text in the password column as a series of ' * '.
However, I noticed that, once this is triggered, the column behind all following the password column to display the user input value as a series of  ' * ' too, including those alrady have data inside the cells.

Thank you.

Regards,
Jenson
0
Svett
Telerik team
answered on 10 Oct 2012, 03:01 PM
Hello Jenson,

This happens due to the editor's caching and RadGridView's UI virtualization. You should improve the code snippets in the following way:
private void radGridView_CellEditorInitialized(object sender, GridViewCellEventArgs e)
{
    GridViewDataColumn dataColumn = e.Column as GridViewDataColumn;
 
    if (dataColumn != null)
    {
        RadTextBoxEditor textBoxEditor = this.radGridView1.ActiveEditor as RadTextBoxEditor;
 
        if (textBoxEditor != null)
        {
            RadTextBoxEditorElement editorElement = textBoxEditor.EditorElement as RadTextBoxEditorElement;
 
            if (dataColumn.UniqueName == "Password")
            {
                editorElement.PasswordChar = '*';
            }
            else
            {
                editorElement.PasswordChar = '\0';
            }
        }
    }
}

If the proposed solution does not address the misleading behavior, I would kindly ask you open support ticket where you can enclose a sample project where the issue occurs. In addition, could you illustrate the exact steps that we should follow to reproduce it. Greetings,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
0
Jenson
Top achievements
Rank 2
answered on 12 Oct 2012, 03:56 AM
Thanks Svett,

Thanks for the helps, it works!

Cheers,
Jenson
0
Kuba
Top achievements
Rank 1
answered on 16 Dec 2013, 11:11 AM
Hi!

This solution is almost great. ;) I found one issue, when you can see password.

When you write password in new line it is obfuscated, but when you move to the next cell it became visible until you end editing new line.
It applies only to new row.

How can I avoid this problem? Is this my fault or code from above works this way?

Cheers,
Kuba.
0
George
Telerik team
answered on 19 Dec 2013, 10:27 AM
Hi Kuba,

Thank you for writing.

You need to subscribe to the CellFormatting event of RadGridView and use the following code (which my colleague provided):
GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
 
if (dataColumn != null && dataColumn.UniqueName == "Password")
{
    object value = e.CellElement.RowInfo.Cells["Password"].Value;
    string text = String.Empty;
    if (value != null)
    {
        int passwordLen = Convert.ToString(value).Length;
        text = String.Join("*", new string[passwordLen]);
    }
 
    e.CellElement.Text = text;
}

You can also find attached below a sample project which demonstrates this functionality.

I hope this helps.

Regards,
George
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Rayan
Top achievements
Rank 1
answered on 25 Oct 2017, 08:07 AM
Perfect! Thank you Svett
Tags
GridView
Asked by
Hari M S
Top achievements
Rank 1
Answers by
Svett
Telerik team
Jenson
Top achievements
Rank 2
Kuba
Top achievements
Rank 1
George
Telerik team
Rayan
Top achievements
Rank 1
Share this question
or