曾经为在DataGridView中设置密码列(显示为*号)而发愁,         /// <summary>
        
/// 单元格显示格式事件
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {
            
// 把第4列显示*号,*号的个数和实际数据的长度相同
            if (e.ColumnIndex == 3)
            {
                
if (e.Value != null && e.Value.ToString().Length > 0)
                {
                    e.Value 
= new string('*',e.Value.ToString().Length);
                }
            }
        }

        
/// <summary>
        
/// 编辑单元格控件事件
        
/// </summary>
        
/// <param name="sender"></param>
        
/// <param name="e"></param>
        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            
// 编辑第4列时,把第4列显示为*号
            TextBox t = e.Control as TextBox;
            
if (t != null)
            {
                
if (this.dataGridView1.CurrentCell.ColumnIndex == 3)
                    t.PasswordChar 
= '*';
                
else
                    t.PasswordChar 
= new char();
            }
        }

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2021-05-30
  • 2021-08-16
  • 2022-01-16
猜你喜欢
  • 2021-09-20
  • 2021-12-24
  • 2022-12-23
  • 2021-08-21
相关资源
相似解决方案