DataGridView 密码列(显示为*号)的设置
来源:互联网 发布:杀手 第一章 网络杀手 编辑:程序博客网 时间:2024/05/04 03:31
曾经为在DataGridView中设置密码列(显示为*号)而发愁,如何把Windows 窗体 DataGridView 的某一列的数据显示为“*”。
哈哈,今天终于搞定了。需要在DataGridView的2个事件中写代码真麻烦!下面的代码把第4列设置为密码列(显示为*号):
哈哈,今天终于搞定了。需要在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();
}
}
/// 单元格显示格式事件
/// </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 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- datagridview 列显示设置
- 设置DataGridView 列类型为 DataGridViewComboBoxColumn 的默认值
- 显示、隐藏DataGridView的列
- DataGridView的列宽设置
- DataGridView的列宽设置
- DataGridView的列宽设置
- DataGridView的列宽设置
- 改变DataGridView列显示顺序,通过设置DisplayIndex来改变显示的顺序
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- 如何把Windows 窗体 DataGridView 的某一列的数据显示为“*”。
- datagridview隐藏不需要显示的列
- _IO,_IOR,_IOW和_IORW的含义
- Patrick Henry Winston 个人主页内容翻译
- 机器启动时, 要按F1的问题
- Delphi与Excel的亲密接触
- MagicAjax的使用方法
- DataGridView 密码列(显示为*号)的设置
- gridview的简单示例
- 编写高效的JAVA程序-编程规范 (中级篇 )
- 如何与咄咄逼人的客户谈判
- 16岁男孩一次风流 “那个”忽然消失不见
- 短信黑幕:某大型门户网站离职人员自曝惊人黑幕
- 转子CSDN Blog
- 已知二叉树的某两种遍历结果,输出另一种遍历的结果(附源码)
- 各位大侠,谁有dom4j的中文文档?