屏蔽datagridview中的密码列 [英] Masking password column in datagridview
本文介绍了屏蔽datagridview中的密码列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在屏蔽密码列时遇到问题.下面的代码可以工作,但是不能按照我想要的方式工作.在编辑它时,它会掩盖密码,但是当我完成操作并继续下一个操作时,下一个datagridviewcell密码将变为可见.
I'm having problem with masking the password column. The code below works, but it doesnt work the way I want. While editing it do mask the password but when I am done and continue to the next datagridviewcell password becomes visible.
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if ( dataGridView1.CurrentCell.ColumnIndex == 5 || dataGridView1.CurrentCell.ColumnIndex == 10)//select target column
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
textBox.UseSystemPasswordChar = true;
}
}
var txtBox = e.Control as TextBox;
txtBox.KeyDown -= new KeyEventHandler(underlyingTextBox_KeyDown);
txtBox.KeyDown += new KeyEventHandler(underlyingTextBox_KeyDown);
}
在编辑模式下,它也应该仅屏蔽索引为5&&的列. 10但是它掩盖了所有列. 我无法解决这些问题,任何帮助都会很棒.
Also in edit mode it should have mask only the columns with index 5 && 10 however it masks all columns. I cannot solve these issues, any help would be great.
推荐答案
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
if ((e.ColumnIndex == 5 || e.ColumnIndex == 10) && e.Value != null)
{
dataGridView1.Rows[e.RowIndex].Tag = e.Value;
e.Value = new String('\u25CF', e.Value.ToString().Length);
}
}
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
if (dataGridView1.CurrentCell.ColumnIndex == 5 || dataGridView1.CurrentCell.ColumnIndex == 10)//select target column
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
textBox.UseSystemPasswordChar = true;
}
}
else
{
TextBox textBox = e.Control as TextBox;
if (textBox != null)
{
textBox.UseSystemPasswordChar = false;
}
}
var txtBox = e.Control as TextBox;
txtBox.KeyDown -= new KeyEventHandler(underlyingTextBox_KeyDown);
txtBox.KeyDown += new KeyEventHandler(underlyingTextBox_KeyDown);
}
这篇关于屏蔽datagridview中的密码列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文