DataGridView 密码列(显示为*号)的设置
来源:互联网 发布:网络新词及意思和出处 编辑:程序博客网 时间:2024/04/23 15:34
本文转载:http://www.cnblogs.com/anjou/archive/2007/02/06/642658.html
曾经为在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();
}
}
/// 单元格显示格式事件
/// </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();
}
}
0 0
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- DataGridView 密码列(显示为*号)的设置
- datagridview 列显示设置
- 设置DataGridView 列类型为 DataGridViewComboBoxColumn 的默认值
- 显示、隐藏DataGridView的列
- DataGridView的列宽设置
- DataGridView的列宽设置
- DataGridView的列宽设置
- DataGridView的列宽设置
- 改变DataGridView列显示顺序,通过设置DisplayIndex来改变显示的顺序
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- 设置DataGridView 显示自己添加编辑的列名,不动态显示数据库本身的列名
- 如何把Windows 窗体 DataGridView 的某一列的数据显示为“*”。
- datagridview隐藏不需要显示的列
- eclipse相关设置
- App内存泄漏问题
- 最长公共子序列(LCS)问题
- C语言数组笔记
- 黑马程序员--字节流
- DataGridView 密码列(显示为*号)的设置
- hibernate 分页的两种方法
- 计算机视觉资源汇总 - Part IV(期刊会议)
- 提交按钮动画效果(基于SVGi)
- java开源工具:网站开发工具清单
- mount: you must specify the filesystem type
- 约瑟夫环算法用面向对象的一种实现
- 为什么要用Bootstrap
- java lesson1