木目心

导航

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);
    }
  }
}

posted on 2022-04-07 16:19  SunSmall  阅读(363)  评论(0编辑  收藏  举报