Displaying a password as a ListView item

  • Thread starter Thread starter Ray Mitchell
  • Start date Start date
R

Ray Mitchell

Hello,

I would like to keep passwords in a ListView item but have them display as
asterisks or som other arbitrary character. This is easy in a text box by
settin the appropriate attribute but there doesn't appear to be such an
attribute for list view items. I have several klugey ideas for how to
accomplish this, for example, using an extra hidden item in the ListView, but
I just wanted to chek on this group first to see if there was a cleaner way.

Thanks,
Ray
 
I did not test this thuroughly, but I think it works as you want.
listView1 needs to be set to OwnerDraw = true.

public Form1()
{
InitializeComponent();
listView1.DrawItem += new
DrawListViewItemEventHandler(listView1_DrawItem);
}

void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
// Draw the item text for views other than the Details view.
if (listView1.View != View.Details)
{
string s = e.Item.Text;
e.Item.Text = "*****************************".Substring(0, s.Length);
e.DrawText();
e.Item.Text = s;
}
}
 
Back
Top