Password entry in ADO datagrid
I use an ADO Datagrid in my VB 6 app.
One of the columns should allow the user to enter a password.
I'd like to use the password functionality of the regular Textbox control which displays "*" for each character entered.
Does anyone know how to do that in a ADO datagrid?
Re: Password entry in ADO datagrid
It sound's a bit tricky, but couldn't you :
1. Find the hwnd of the edit control used (it's a standard windows 'edit' window)
2. Change the style of the text control to ES_PASSWORD
The tricky part would be '1' above, as you'd need to Enum / FindWindow first depending on what column you are in.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Re: Password entry in ADO datagrid
Thanks,
that sounds like it could work.
Unfortunately it requires much more work and time than I can afford at present.
Also, I think that the Edit Control is dynamically created and destroyed, whenever you change cells...
Re: Password entry in ADO datagrid
I know that this is a fudge and I have never used the DATA grid but for now could you not just add another invisible column to the grid and use the keypress event to first of all to add the Chr$(KeyAscii) to the invisible column and then set KeyAscii = 42 whenever a user types in your password column. Then you can do validation against the invisible column.
Re: Password entry in ADO datagrid
not a bad idea, thanks.
OTOH just trapping keyPress isn't enough. The user might also move the arrow, select text portions with the mouse and so on.
This sounds even like more work than finding the Edit control.
Re: Password entry in ADO datagrid
Why not try and use a self made kind of inputbox whenever the user activates the field. You can use a textfield in it, wich has the passwordchar property. When he presses OK return the value to the hidden field (wich the anonymous person suggested), and display *'s in the visible (dummy) field.
Tom Cannaerts
[email protected]
The best way to escape a problem, is to solve it.
Re: Password entry in ADO datagrid
That sounds like an improvement to Anyonymous's replay.
Still, I'd have to take scrolling into account. If the user scrolls within the grid, I'll have to move the Input box, too.
Thanks for your input.
Re: Password entry in ADO datagrid
Chris,
I've done some "research".
The datagrid has a hwndEditor property which is the hwnd of the editor window (it's of class "Edit"). It has a valid value as soon as the ColEdit Event is raised.
Still, I can't set the style to ES_PASSWORD, because - according to the docs - that style cannot be set after the control has been created.
(SetWindowLong fails).
Sending EM_PASSWORDCHAR messages works only for controls with the ES_PASSWORD style set.
I'm stuck.
Re: Password entry in ADO datagrid
I'm stuck too :)
I remember Matt Hart (http://www.matthart.com), or it might have been Matt Curland (http://www.vbpj.com), writing some code a while back that allowed you to trap (subclass) windows in VB, the moment they were created (some very lowlevel stuff). If you (or I) can find that code, it might be able to help.
Having said all that, the other 'thread' might be the way to go (using your own textbox control) - I've only ever done this with the flexgrid, and that was quite a bit of work as well.
Chris Eastwood
CodeGuru - the website for developers
http://codeguru.developer.com/vb
Re: Password entry in ADO datagrid
I can't see the problem with scrolling within the grid as the arrow keys are not trapped in the keypress event.
As for users selecting certain amount of your password field it's not that difficult to have your own pop up menu appear so that they can't cut/copy/paste/delete etc.
I have to say though that I'm not sure about the windows shortcuts like Ctlr+C etc so that may be a problem.