Search code examples
c#datagridviewpasswordsmasking

Showing password data in DataGridView when clicked


i'm just new to c# and visual studio

so i figured how to mask the password in my datagridview with this

private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (e.ColumnIndex == 5  && e.Value != null)
        {
            dataGridView.Rows[e.RowIndex].Tag = e.Value;
            e.Value = new String('\u25CF', e.Value.ToString().Length);

        }
    }

Now i wanted to show the password again when i click on the cell, i figured it would be on dataGridView_CellClick event but i can't figure how to make it show up again. do i assign it to e.Value again?


Solution

  • use a textbox by design in that column of gridview and from source add a checkbox too !

    then use this code

    private void FromSourceAddedCheckBox_CheckedChanged(object sender, EventArgs e)
    {
        if (FromSourceAddedCheckBox.Checked == true)
        {
            GridviewTextboxID.UseSystemPasswordChar = true;
        }
        else 
        {
            GridviewTextboxID.UseSystemPasswordChar = false;
        }
    }