我有一个数据网格视图控件。现在我有两个文本框列。其中第一个我设置为密码。问题是,每当我尝试在另一个文本框中编辑某些内容时,它同样会显示在蒙版文本中。如何避免这种情况?
我的代码如下
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 1)
{
TextBox tb = e.Control as TextBox;
if (tb != null)
{
tb.PasswordChar = '*';
}
}
}
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if (e.ColumnIndex == 1 && e.Value != null)
{
e.Value = new string('*', e.Value.ToString().Length);
}
}