DataGridView 密码列(显示为*号)的设置
2007-11-12 10:28
363 查看
曾经为在DataGridView中设置密码列(显示为*号)而发愁,如何把Windows 窗体 DataGridView 的某一列的数据显示为“*”。
哈哈,今天终于搞定了。需要在DataGridView的2个事件中写代码真麻烦!下面的代码把第4列设置为密码列(显示为*号):
/// <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();
}
}
哈哈,今天终于搞定了。需要在DataGridView的2个事件中写代码真麻烦!下面的代码把第4列设置为密码列(显示为*号):
/// <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();
}
}
相关文章推荐
- C# -- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- [导入]DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- 动态设置EditText密码的显示和隐藏
- datagridview设置默认单元格格式用以显示特定时间格式
- Android 设置EditText显示或隐藏密码
- 设置datagridview的某个checkbox不显示
- EditText内容加入设置字体导致的输入密码显示为透明
- Android EditText 显示或隐藏密码,增加边框,设置光标操作
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- EditText的换行输入、输入起始位置、调用指定格式的系统键盘(显示和隐藏),光标颜色,密码动态设置可见性
- EditText设置点击按钮显示与隐藏密码
- 开机显示或不显示用户登录密码输入界面,不设置密码亦可显示