如何在GridView控件创建类型的密码列? [英] How to create column of type password in gridview?

查看:399
本文介绍了如何在GridView控件创建类型的密码列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建在用户选择文件并提供凭据打开该文件的应用程序。对于我在一个GridView创建三列。结果
的用户在密码栏输入密码。结果
我想显示的 * 到位的人物,如我们可以创建密码类型的文本框的结果
我已经尝试了 GridView_CellClick 事件的代码:

I am creating an application in which user selects files and provides credentials to open that file. For that I have created three columns in a gridview.
User enters password in password column.
I want to display * in place of characters like we can create a textbox of password type.
I have tried this code on GridView_CellClick event :

if (GridView.Columns[e.ColumnIndex].HeaderText == "Password")
{ 
   txtPassword[e.RowIndex] = new TextBox();
   txtPassword[e.RowIndex].Name = "txtPassword"+e.RowIndex;
   txtPassword[e.RowIndex].PasswordChar = '*';
   txtPassword[e.RowIndex].Visible = true;
   txtPassword[e.RowIndex].TextChanged += new      

   if (GridView.CurrentCell.Value == null)
      txtPassword[e.RowIndex].Text = "";
   else
      txtPassword[e.RowIndex].Text = GridView.CurrentCell.Value.ToString();

   txtPassword[e.RowIndex].Location = GridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex + 1, false).Location;

   txtPassword[e.RowIndex].Size = GridView.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex + 1, false).Size;

   txtPassword[e.RowIndex].Visible = true;
   txtPassword[e.RowIndex].Focus();
} 



但在上述溶液字符显示。结果
如何?我能解决这个问题。

But in above solution characters are displayed.
How can I solve this problem?

推荐答案

我觉得它应该工作处理EditingControlShowing事件,并在处理程序中添加以下代码:

I think it should work to handle the EditingControlShowing event and in the handler add the following code:

if(e.ColumnIndex == 2)
{
    TextBox tb = e.Control as TextBox;
    if (tb != null)
    {
        tb.PasswordChar = '*';
    }
}



CellFormatting事件处理程序代码:

CellFormatting Event Handler code:

if(e.ColumnIndex = 2)
{
    if(e.Value != null)
    {
        e.Value = New string("*", e.Value.ToString().Length);
    }
}



而在这个事件e应该有一个参数:columnIndex属性: )

And in this event e should have a ColumnIndex property :)

这篇关于如何在GridView控件创建类型的密码列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆