如何设置DataGridViewTextBoxColumn的密码属性
本文关键字:DataGridViewTextBoxColumn 密码 属性 设置 何设置 | 更新日期: 2023-09-27 18:05:59
我使用DataGridView
实现用户名-密码UI。密码在"DataGridViewTextBoxColumn
类型"列中显示。我如何使用现有的代码DataGridViewTextBoxColumn
和实现密码属性的文本?
处理EditingControlShowing
事件,然后将编辑控件转换为TextBox
并手动将UseSystemPasswordChar
设置为true:
TextBox passwordText = e.Control as TextBox;
if (passwordText != null)
{
passwordText.UseSystemPasswordChar = true;
}
<标题>编辑你可以试试这个吗:
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (dataGridView1.Columns[e.ColumnIndex].Name == “passwordDataGridViewTextBoxColumn” && e.Value != null)
{
dataGridView1.Rows[e.RowIndex].Tag = e.Value;
e.Value = new String(‘*’, e.Value.ToString().Length);
}
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentRow.Tag != null)
e.Control.Text = dataGridView1.CurrentRow.Tag.ToString();
}
标题>if (e.ColumnIndex >= 0)
{
if (dataGridView.Columns[e.ColumnIndex].Name == "Password" && e.Value != null)
{
dataGridView.Rows[e.RowIndex].Tag = e.Value;
e.Value = new String(''u2022', e.Value.ToString().Length);
}
}