Home Forums WinForms controls Xceed Grid for WinForms column of type password?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #15109 |

    Is there a way to have a column in a grid display with “******” instead of the actual data, like a password field in a login screen?

    Imported from legacy forums. Posted by Phil (had 4457 views)

    User (Old forums)
    Member
    Post count: 23064

    You will need to implement that manually, for the grid does not provide any feature to do this automatically (i.e. by setting a property). You can use the LeavingEdit event on the cell to accomplish this, or do it directly in the editor if you want to mask characters as they are typed.

    Imported from legacy forums. Posted by André (had 2807 views)

    User (Old forums)
    Member
    Post count: 23064

    Is this still true of version 3.8?  Also, is there a sample somewhere of how masking is accomplished (haven’t done that sort of thing yet)?

    Thanks!

    Peace, Love, and Light,

    /s/ Jon C. Munson II

    Imported from legacy forums. Posted by Jon (had 1574 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi!

    To make a cell showing its content as a masked password (i.e. “*******”), one possibility is:
     
    DataRow dataRow;
    // gridControl1 being the default grid name when dropped on a form, could be something else 
    dataRow = this.gridControl1.DataRows.AddNew();
    // WinTextBox is defined in Xceed.Editors so make you have a reference and a “using” directive
    WinTextBox wtb = new WinTextBox();
    // Add Xceed.Grid.Editors and Xceed.Grid.Viewers (as above)
    // “Editors” being the name of the column containing this password field
    dataRow.Cells[“Editors”].CellEditorManager = new TextEditor(wtb);
    dataRow.Cells[“Editors”].CellViewerManager = new TextViewer(wtb);
    dataRow.Cells[“Editors”].CellViewerManager.SettingControlAppearance += new CellViewerEventHandler(CellViewerManager_SettingControlAppearance);
     
    with
     
    void CellViewerManager_SettingControlAppearance(object sender, CellViewerEventArgs e)
    {
      WinTextBox winTextBox = e.Control as WinTextBox;
      winTextBox.TextBoxArea.PasswordChar = ‘*’;
     
    as the event handler to set the password character.
     
    It could be a good thing to have another cell just next to this one to validate the password entered in the first cell, since the user won’t see what he is typing.
     
    The code above is for a single row.  To apply this a password field cell to each row, simply address the column itself:
     
    WinTextBox wtb = new WinTextBox();
    this.gridControl1.Columns[“Password”].Title = “Password”;
    this.gridControl1.Columns[“Password”].CellEditorManager = new TextEditor(wtb);
    this.gridControl1.Columns[“Password”].CellViewerManager = new TextViewer(wtb);
    this.gridControl1.Columns[“Password”].CellViewerManager.SettingControlAppearance += new CellViewerEventHandler(CellViewerManager_SettingControlAppearance);
     
    keeping the same event handler as above:
     
    void CellViewerManager_SettingControlAppearance(object sender, CellViewerEventArgs e)
    {
      WinTextBox winTextBox = e.Control as WinTextBox;
      winTextBox.TextBoxArea.PasswordChar = ‘*’;

     

     

     

    Imported from legacy forums. Posted by Ghislain (had 2989 views)

    User (Old forums)
    Member
    Post count: 23064

    The solution works fine but still there’s a small problem with it.

    The style (border color, border width, font, etc…) of the cell becomes different from my other cells.

     I haven’t found a way to “copy” the style of my other cells into the cells with the “PasswordChar” feature.

     Any suggestions ?

    Serge

    Imported from legacy forums. Posted by Serge (had 287 views)

    User (Old forums)
    Member
    Post count: 23064

    Nevermind my question, I found the problem.

    The border style of the control generated when creating my new CellViewManager was set to UIStyle instead of None.

     Serge

    Imported from legacy forums. Posted by Serge (had 1632 views)

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.