Editable Password Fields in REALbasic

| | Comments (1)

So I needed the ability to make a cell editable in an RB listbox, but make it a password field. So after consulting Dave and Jon, we came up with a great solution.

First, in the open event, make the proper column editable (in my case it's column 2) like this:
[rbcode]
me.ColumnType( 2 ) = ListBox.TypeEditable
[/rbcode]

Then in the Listbox.CellGotFocus event, you put the following:
[rbcode]
if column = 2 then
me.ActiveCell.Password = true
else
me.ActiveCell.Password = false
end
[/rbcode]

This causes the editable cell to show up as a password editfield. The only problem left to solve is that once you're done editing the field (and commit the change), the listbox will try to just render the editfield's text as usual (ignoring the Password property). So you place this code in the CellTextPaint event:
[rbcode]
if column = 2 then
g.DrawString( "******", x, y )
return true
end
return false
[/rbcode]

Voila! Nou now have a ListBox that has editable password cells in it. Isn't that just a handy little thing to do?

1 Comments

Great tip Aaron, thanks....

Leave a comment

Disclaimer

I'm currently an employee of REAL Software. My blog is mine. The opinions represented in this blog are mine as well and may not represent my employer's opinions. All original material is copyrighted and property of the author.

REALbasic® is a registered trademark of REAL Software, Inc. REAL SQL Server™ and Lingua™ are pending trademarks of REAL Software, Inc. All rights reserved.