Password masking in individual Datagrid Cells

G

Guest

I have an XML driven datagrid that displays configuration data. To hide particlular sensitive information I would like to mask particular cells with a password char like "*".

I can "color" out the data for particular cells by inheriting a class from DataGridTextBoxColumn and adding some code to the the paint event.

But I would rather use some form of password masking. I have tried setting the PasswordChar property of the underlying DataGridTextBox. However, this works only for the selected cell as it seems the instance of the DataGridTextBox is created and destroyed when cells are selected. When I select a new cell the data in the old masked cell appears again

Does anyone know how I could to this?
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi David,

You can create a new column style derived from DataGridTextBoxColumn and
override its PaintText method.
When you need to mask a cell, call base.PaintText and pass the appropriate
number of asterisks as the "text" argument value.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

David Stewart-Thomson said:
I have an XML driven datagrid that displays configuration data. To hide
particlular sensitive information I would like to mask particular cells with
a password char like "*".
I can "color" out the data for particular cells by inheriting a class from
DataGridTextBoxColumn and adding some code to the the paint event.
But I would rather use some form of password masking. I have tried
setting the PasswordChar property of the underlying DataGridTextBox.
However, this works only for the selected cell as it seems the instance of
the DataGridTextBox is created and destroyed when cells are selected. When
I select a new cell the data in the old masked cell appears again.
 
G

Guest

Dmitriy - Thanks - that solved my problem - I can't seem to override the PaintText event but I can the paint event so have put the call to Mybase.PaintText in there

----- Dmitriy Lapshin [C# / .NET MVP] wrote: ----

Hi David

You can create a new column style derived from DataGridTextBoxColumn an
override its PaintText method
When you need to mask a cell, call base.PaintText and pass the appropriat
number of asterisks as the "text" argument value

--
Dmitriy Lapshin [C# / .NET MVP
X-Unity Test Studi
http://www.x-unity.net/teststudio.asp
Bring the power of unit testing to VS .NET ID

David Stewart-Thomson said:
I have an XML driven datagrid that displays configuration data. To hid
particlular sensitive information I would like to mask particular cells wit
a password char like "*"setting the PasswordChar property of the underlying DataGridTextBox
However, this works only for the selected cell as it seems the instance o
the DataGridTextBox is created and destroyed when cells are selected. Whe
I select a new cell the data in the old masked cell appears again
 

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