Masking password column in datagridview

前端 未结 2 912
遇见更好的自我
遇见更好的自我 2020-12-20 03:31

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 c

2条回答
  •  既然无缘
    2020-12-20 04:14

    Assuming the the name of your DataGridView is dataGridView1 and the password column is 1, add this to CellFormatting:

    private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 1 && e.Value != null)
        {
            e.Value = new String('*', e.Value.ToString().Length);
        }
    }
    

提交回复
热议问题