Password Characters in a DataGridView column

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • JB

    #1

    Password Characters in a DataGridView column

    Hi All,

    I'd like to display password characters in a DataGridView column, the
    same way I can do in a standard TextBox by using the PasswordChar
    property (i.e.typed characters replaced by a star for instance).

    Can anyone tell me how?

    Thanks
    JB
  • JB

    #2
    Re: Password Characters in a DataGridView column

    On 20 Sep, 14:22, JB <jb.bross...@gm ail.comwrote:
    Hi All,
    >
    I'd like to display password characters in a DataGridView column, the
    same way I can do in a standard TextBox by using the PasswordChar
    property (i.e.typed characters replaced by a star for instance).
    >
    Can anyone tell me how?
    >
    Thanks
    JB
    Hi All,

    For those who are interested, I've figured out a "manual" solution for
    this problem.
    If you find a more elegant (and simpler) way to do it, please let me
    know.

    0) When first displaying my DataGridView (DGV) I initialise both the
    Tag and Value property of the cell with the Password

    1) In the EditingControlS howing event, I set the PasswordChar property
    of the Editing Control
    CType(DGV.Editi ngControl, TextBox).Passwo rdChar = "*"

    2) In the CellValidated event (i.e. just before leaving the cell in
    edit mode) I save the Password in the Cell's Tag Property
    And I also clear the PasswordChar property of the EditingControl
    Dim PasswordBox As TextBox = CType(DGV.Editi ngControl,
    TextBox)
    If PasswordBox IsNot Nothing Then
    DGV.Rows(e.RowI ndex).Cells(e.C olumnIndex).Tag =
    PasswordBox.Tex t
    PasswordBox.Pas swordChar = Nothing
    End If

    3) In the CellFormatting event (i.e. when the cell needs to format its
    value for display) I mask the content with the password char
    With DGV.Rows(e.RowI ndex).Cells(e.C olumnIndex)
    .Value = New String("*", TryCast(.Tag, String).Length)
    End With

    Of course this code is only executed if the events are called for the
    relevant column (i.e. the one storing the password)

    JB

    Comment

    Working...