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

作者tag: .net  c#  datagrid  windows/.net  gridview  精髓  .net c#基础语法  .net 控件-web基本控件  .net 专题-报表图表  .net 专题-数据控件-gridview  .net c#精髓【月儿原创】  .net 专题-数据控件-datagrid  .net 技术-ado.net 数据访问 CSDN 推荐tag: w3c  sqlcon  tcheader  代码  boundfield  gridview1  数据  控件  技巧 

<script type="text/javascript">function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>

曾经为在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();
            }
        }

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1537000


<script src="http://localhost:82/PromoteIcon.aspx?id=1537000" type="text/javascript"></script> [ 收藏到我的网摘]   清清月儿发表于 2007年03月22日 02:48:00
 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值