views:

374

answers:

4

Is there a ways to transform text that is in a specific column of a listview control into password characters? Thank you.

A: 

Windows does not support it, but those "passwords character" as you call it, are actually a unicode char, so you can build your own system for that. Something like inheriting ListView, then keep in a private field the real text, and replace the cell's text with those dots.

I don't exactly remember the whole structure of ListView, and ListViewItem, or what ever it is... but you'll probably need to do a lot of overriding and hiding, inherting at least ListView, and maybe ListViewItem as well.

I think you'll manage to do this by your own. If not, edit your question :)

Itay
I hate listviews haha, so confusing after a while. Any chance you can give me a start with this?
Nate Shoffner
+3  A: 

I would store the actual data (password in this case) in the ListViewItem's Tag property. Then you can put whatever you like in the Text field. This pattern works well in general for associating objects with items in other types of list/grid controls.

String password = "MyPassword";
ListViewItem lvi = new ListViewItem("********");
lvi.Tag = password;

listView.Items.Add(lvi);
Jerry Fernholz
A: 

If it's an output field, you just do the change to '*' when you fill the field. If it's one that the user is entering, you need to attach to the keydown event and make the substitution there.

You'll need to identify at least one other field (User Name, User ID, whatever...) to act as a map so you know what the real value in the field is, if you want to use the actual password. You can do that with a Hashtable object.

jfawcett
+1  A: 

Use an ObjectListView (an open source wrapper around .NET WinForms ListView). It makes almost everything about a ListView far less painful -- it's even fun sometimes.

In this case, you would use an AspectToStringConverter delegate, which is responsible for converting a value into the string you want to appear in the ListView:

this.olv1.passwordColumn.AspectToStringConverter = delegate(object value) {
    string password = (string)value;
    if (String.IsNullOrEmpty(password))
        return String.Empty;
    else
        return new String('*', password.Length);
}
Grammarian