您的位置:首页 > 其它

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

2009-05-05 15:55 218 查看
/// <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();

            }

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: