c# - Masking password column in datagridview -
i'm having problem masking password column. code below works, doesnt work way want. while editing mask password when done , continue 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 textbox; if (textbox != null) { textbox.usesystempasswordchar = true; } } var txtbox = e.control textbox; txtbox.keydown -= new keyeventhandler(underlyingtextbox_keydown); txtbox.keydown += new keyeventhandler(underlyingtextbox_keydown); }
also in edit mode should have mask columns index 5 && 10 masks columns. cannot solve these issues, 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 textbox; if (textbox != null) { textbox.usesystempasswordchar = true; } } else { textbox textbox = e.control textbox; if (textbox != null) { textbox.usesystempasswordchar = false; } } var txtbox = e.control textbox; txtbox.keydown -= new keyeventhandler(underlyingtextbox_keydown); txtbox.keydown += new keyeventhandler(underlyingtextbox_keydown); }
Comments
Post a Comment