Display column in DataGridView as password input type
10,975
You can handle the EditingControlShowing
event and then cast the editing control to a TextBox and manually set the UseSystemPasswordChar to true.
private void dataGridView1_EditingControlShowing(object sender,
DataGridViewEditingControlShowingEventArgs e)
{
if(e.ColumnIndex == 3)//select target column
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
textBox.UseSystemPasswordChar = true;
}
}
}
Related videos on Youtube
Author by
Emil Dumbazu
Updated on June 25, 2022Comments
-
Emil Dumbazu almost 2 years
I would like to display a column in a datagridview as a column which contains password chars.I cannot figure it out why does this event is not triggered by the datagridview.
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) { if(e.ColumnIndex == 3) { if(e.Value != null) { e.Value = new string('*', e.Value.ToString().Length); } } }
Help please.
-
disasterkid about 9 yearsCorrect me if I am wrong but my
e
does not have aColumnIndex
property. -
Denis Molodtsov almost 9 yearsyou could write if(grid.CurrentCell.ColumnIndex == 3 instead of if(e.ColumnIndex == 3)