winform datagridview 如何让其中密码一列用* 替换显示
2个回答
展开全部
private static int passwordColIndex = 0;//根据需要设定你的密码列
//添加事件1
private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
int i = this.dataGridView1.CurrentCell.ColumnIndex;
if (i == passwordColIndex)
{
TextBox txt = e.Control as TextBox;
if (txt != null)
{
txt.UseSystemPasswordChar = true;
}
}
}
//添加事件2
private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
string s = e.Value as string;
if (e.ColumnIndex == passwordColIndex)
{
e.Value = "".PadLeft(s.Length, '*');
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询