加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

DataGridView 密码列(显示为*号)的设置

发布时间:2020-12-16 23:32:55 所属栏目:大数据 来源:网络整理
导读:/// DataGridView 的某一列的数据显示为“*” 。--- DataGridView中设置密码列(显示为*号) ///把第4列设置为密码列(显示为*号): /// summary /// 单元格显示格式事件 /// /summary /// paramname="sender"/param /// paramname="e"/param private void

///DataGridView 的某一列的数据显示为“*”。---DataGridView中设置密码列(显示为*号)
///把第4列设置为密码列(显示为*号):

///<summary>
///单元格显示格式事件
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoiddataGridView1_CellFormatting(objectsender,DataGridViewCellFormattingEventArgse)
{
//把第4列显示*号,*号的个数和实际数据的长度相同
if(e.ColumnIndex==3)
{
if(e.Value!=null&&e.Value.ToString().Length>0)
{
e.Value
=newstring('*',e.Value.ToString().Length);
}
}
}

///<summary>
///编辑单元格控件事件
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
privatevoiddataGridView1_EditingControlShowing(objectsender,DataGridViewEditingControlShowingEventArgse)
{
//编辑第4列时,把第4列显示为*号
TextBoxt=e.ControlasTextBox;
if(t!=null)
{
if(this.dataGridView1.CurrentCell.ColumnIndex==3)
t.PasswordChar
='*';
else
t.PasswordChar
=newchar();
}
}

'vb.net code:

Private Sub DataGridView1_CellFormatting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
If e.ColumnIndex = 3 Then
If e.Value = "" And e.Value.ToString.Length > 0 Then
e.Value = New String("*",e.Value.ToString.Length)
End If
End If

End Sub

Private Sub DataGridView1_EditingControlShowing(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DataGridView1.EditingControlShowing
Dim t As TextBox
t = e.Control

If Not t Is Nothing Then If Me.DataGridView1.CurrentCell.ColumnIndex = 3 Then t.PasswordChar = "*" Else t.PasswordChar = New Char() End If End If End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读