You can create a custom cell and column and use a text field with a password mask as an edit control.
To get around returning clear text when you exit edit mode, you can save the actual password value in a separate property of the cell, and in the GetFormattedValue event (I suppose) you can return a string consisting entirely of "*" to mask the normal display.
Protected Overrides Function GetFormattedValue(ByVal value As Object, ByVal rowIndex As Integer, ByRef cellStyle As System.Windows.Forms.DataGridViewCellStyle, ByVal valueTypeConverter As System.ComponentModel.TypeConverter, ByVal formattedValueTypeConverter As System.ComponentModel.TypeConverter, ByVal context As System.Windows.Forms.DataGridViewDataErrorContexts) As Object Dim strVal As String strVal = New String(CChar("*"), value.ToString.Length) Return MyBase.GetFormattedValue(strVal, rowIndex, cellStyle, valueTypeConverter, formattedValueTypeConverter, context) End Function Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, _ ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle) MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, _ dataGridViewCellStyle) Dim ctl As PasswordTextBoxEditingControl = _ CType(DataGridView.EditingControl, PasswordTextBoxEditingControl) If IsDBNull(Me.Value) Then ctl.Text = "" Else ctl.Text = CType(Me.Value, String) ctl.PasswordChar = "*" ctl.Mask = "*" End If End Sub
for more information on what you are trying to do, visit this: http://www.vbforums.com/showthread.php?t=554744
source share