C# winform DataGridView 一列显示星号
private void myDataGrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
System.Windows.Forms.TextBox t = e.Control as System.Windows.Forms.TextBox;
if (t != null)
{
if (this.myDataGrid.CurrentCell.ColumnIndex == 13)
t.PasswordChar = '*';
else
t.PasswordChar = new char();
}
}
private void myDataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
// 把第13列显示*号,*号的个数和实际数据的长度相同
if (e.ColumnIndex == 13)
{
if (e.Value != null && e.Value.ToString().Length > 1)
{
e.Value = new string('*',e.Value.ToString().Length);
}
}
}