Datagridview

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
owinsloe
Posts: 96
Joined: Tue Jul 10, 2012 10:37 am

Datagridview

Post by owinsloe »

Hi folks, newbie to both PS & primalforms. I have constructed a dataviewgrid that will be filled by windows credentials and require a user to submit their password for authentication purposes. I want to capture keystrokes to convert the characters to "*" (similar to using the textbox passwordchar = '*').I have 2 password columns; the first visible and editable to allow the user to enter their password and the second that is not visible that will hold the cleartext password to allow me to use to programmatically perform authentication (their account ID is in another column)To achieve this I am trying to bind a keypress event to the visible password using EditingControlShowing events and after much searching see there are a few considerations, especially in the area of reusing events on datagridview. I have found a C example (http://stackoverflow.com/questions/8659 ... agrid-view) but not familiar with C or the ability to change this equivalent PS code.The code in the example is not exactly what I want but if someone was able to show me the powershell equivalent then I can work with that. Alternatively if anyone has another powershell example of where they have bound keypress events to a datagridview cell then I could use this.Many thanks in advance.

User avatar
owinsloe
Posts: 96
Joined: Tue Jul 10, 2012 10:37 am

Datagridview

Post by owinsloe »

Hi folks, newbie to both PS & primalforms. I have constructed a dataviewgrid that will be filled by windows credentials and require a user to submit their password for authentication purposes. I want to capture keystrokes to convert the characters to "*" (similar to using the textbox passwordchar = '*').I have 2 password columns; the first visible and editable to allow the user to enter their password and the second that is not visible that will hold the cleartext password to allow me to use to programmatically perform authentication (their account ID is in another column)To achieve this I am trying to bind a keypress event to the visible password using EditingControlShowing events and after much searching see there are a few considerations, especially in the area of reusing events on datagridview. I have found a C example (http://stackoverflow.com/questions/8659 ... agrid-view) but not familiar with C or the ability to change this equivalent PS code.The code in the example is not exactly what I want but if someone was able to show me the powershell equivalent then I can work with that. Alternatively if anyone has another powershell example of where they have bound keypress events to a datagridview cell then I could use this.Many thanks in advance.

jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

Why not just use the password control that does all of this for you?

jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

But why do this?
We have many mechanisms for protecting passwords. Why invent a new one?

jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

Create a dialog.

Why would a user need ti login? A domain gives users a constant login. What is it you are doing thst needs numerous grid records of a user login. Datagridview is control for displaying data not a login form.

Create a dialog iwtrh a text control for user name and a textbox/password control for the password. Gather the info and move on.



jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

Very strange!

I know of no way to do what you are trying to do.

Perhaps you need to try a different approach.


User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Datagridview

Post by davidc »

Try the following on the DataGridView's CellFormatting event:$datagridview1_CellFormatting=[System.Windows.Forms.DataGridViewCellFormattingEventHandler]{#Event Argument: $_ =
[System.Windows.Forms.DataGridViewCellFormattingEventArgs] if ($_.ColumnIndex -eq 0 -and $_.Value -ne $null) { $_.Value = '*' * $_.Value.ToString().Length; }} You can either use the Column's index or name to determine if it should show the alternate characters. David
David
SAPIEN Technologies, Inc.

jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

Hah! - I just remembered how to fo this. I was compketely forgetting how keystroke events have always worked.
uploads/2491/DemoDataGridView.txtjvierra2012-07-14 07:56:37

User avatar
owinsloe
Posts: 96
Joined: Tue Jul 10, 2012 10:37 am

Datagridview

Post by owinsloe »

YOU BEAUTY!!!!That is exactly what I was after....thankyou so much!

jvierra
Posts: 14668
Joined: Tue May 22, 2007 9:57 am
Answers: 5
Has voted: 1 time
Been upvoted: 5 times
Contact:

Datagridview

Post by jvierra »

David - that is interesting.
I suspect we can get the control added event to do that also amd filter by column or column name.


Locked