Displaying a password as a ListView item

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
 
F

Family Tree Mike

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top