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 EditingControlShowing event, I set the PasswordChar property
of the Editing Control
CType(DGV.EditingControl, TextBox).PasswordChar = "*"
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.EditingControl,
TextBox)
If PasswordBox IsNot Nothing Then
DGV.Rows(e.RowIndex).Cells(e.ColumnIndex).Tag =
PasswordBox.Text
PasswordBox.PasswordChar = 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.RowIndex).Cells(e.ColumnIndex)
.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