473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Display decrypted text in databound controls

Hi

I have a table in an sql database that contains data that has been encrypted
using the DPAPI.

What I am trying to achieve is to bind several controls on a vb 2005 windows
form to those fields but display the decrypted data in the controls instead
of the encrypted data. I also want to use a binding navigator to scroll
through the records and to add/delete records. I don't have a problem with
the encryption/decryption but am having trouble doing it dynamically with the
bound controls.

I have tried using several of the bindingsource events but they seem occur
when opening the form or at other times.

Any assistance would be appreciated.
Ian
Jan 21 '07 #1
7 1717
Hi Ian,

This normally varies based on the databound controls. For simple
databinding, such as TextBox, you may use Binding.Parse/Format events to
customize the display in the TextBox. In Binding.Format event, you may
decrypt the underlying encrypted data and display the result clear text to
the UI. In Binding.Parse event, you should do the opposite: get the text in
the UI TextBox and encrypt it. The final encrypted data will be pushed into
the underlying datasource. The article below talks more details of the
Binding.Parse/Format events:
"Data binding concepts in .NET windows forms"
http://www.codeproject.com/vb/net/da...ngconcepts.asp

For DataGridView complex databinding, it provides similar
DataGridView.CellParsing/CellFormatting events which can leverage with the
same logic above.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 22 '07 #2
Hi Ian,

Thanks for your feedback.

I originally provided some sample code regarding using Binding.Parse/Format
events in the link below, for your information:
http://groups.google.com/group/micro...rk.windowsform
s.databinding/msg/a429f83e8a552123?hl=en&

Also, the article I provided in the last reply also contains sample code in
VB.net regarding how to use Binding.Parse/Format events:
"Data binding concepts in .NET windows forms"
http://www.codeproject.com/vb/net/da...ngconcepts.asp

I can not find a dedicate article regarding the usage of
DataGridView.CellParsing/CellFormatting events. Basicly, you may select
DataGridView control in the VS2005 designer and click the event icon in the
PropertyBrowser and find CellParsing/CellFormatting events in the event
list. Then you may double click to add an event handler for these 2 events.

Below is the official link for DataGridView.CellParsing event, which
contains the most useful guidelines and sample code regarding its usage:
http://msdn2.microsoft.com/en-gb/lib...datagridview.c
ellparsing.aspx

Anyway, if you still have any problem of getting this work for you, please
feel free to tell me, I will work with you, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '07 #3
Here's an example from a posting I made back in November 2006 for
capturing and using the Format and Parse events on a DataGridView.

The OP was trying to change how the data is displayed, but
not how it's stored, so if the user puts in "75000", he wanted
it displayed as "75K", but stored as 75000. And when it's
brought in from the database, he wanted to convert it from
75000 to 75K. When it's put back, he wanted to translate it
the other way.

CellFormatting happens between the data source and the screen.
CellParsing happens between the screen and the data source.

Try this:

AddHandler myGrid.CellFormatting, AddressOf OnCellFormatting
AddHandler myGrid.CellParsing, AddressOf OnCellParsing

Private Sub OnCellFormatting(ByVal object as Sender, _
ByVal e as DataGridViewCellFormattingEventArgs)

If e.ColumnIndex = myGrid.Columns("columnIcareAbout") Then
'setting this to true signals the grid that this
' column is being dynamically updated. If you don't
' do this, you will get an infinite loop if you have
' also set the column to have its size automatically
' determined.
e.FormattingApplied = True

'get the row being populated; format this cell
Dim row as DataGridViewRow = myGrid.Rows(e.RowIndex)
If e.Value = "75000" Then
e.Value = "75K"
End If
End If
End Sub

Private Sub OnCellParsing(ByVal object as Sender, _
ByVal e as DataGridViewCellParsingEventArgs)

If e.ColumnIndex = myGrid.Columns("columnIcareAbout") Then
'get the row being populated; format this cell
Dim row as DataGridViewRow = myGrid.Rows(e.RowIndex)
If e.Value = "75K" Then
e.Value = "75000"
End If
End If
End Sub

Hope this helps.
Robin S.
-------------------
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:BX**************@TK2MSFTNGHUB02.phx.gbl...
Hi Ian,

Thanks for your feedback.

I originally provided some sample code regarding using
Binding.Parse/Format
events in the link below, for your information:
http://groups.google.com/group/micro...rk.windowsform
s.databinding/msg/a429f83e8a552123?hl=en&

Also, the article I provided in the last reply also contains sample
code in
VB.net regarding how to use Binding.Parse/Format events:
"Data binding concepts in .NET windows forms"
http://www.codeproject.com/vb/net/da...ngconcepts.asp

I can not find a dedicate article regarding the usage of
DataGridView.CellParsing/CellFormatting events. Basicly, you may
select
DataGridView control in the VS2005 designer and click the event icon
in the
PropertyBrowser and find CellParsing/CellFormatting events in the
event
list. Then you may double click to add an event handler for these 2
events.

Below is the official link for DataGridView.CellParsing event, which
contains the most useful guidelines and sample code regarding its
usage:
http://msdn2.microsoft.com/en-gb/lib...datagridview.c
ellparsing.aspx

Anyway, if you still have any problem of getting this work for you,
please
feel free to tell me, I will work with you, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 23 '07 #4
Hi Robin,

Thank you for sharing your code snippet!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 23 '07 #5
You're welcome. In all fairness, I figured that out with the help
of Brian Noyes' Data Binding book. It has some really cool stuff in it.

Robin S.
-------------------------------
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:zc**************@TK2MSFTNGHUB02.phx.gbl...
Hi Robin,

Thank you for sharing your code snippet!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 23 '07 #6
Hi Robin ,

Yes, this is really a good book. As far as I know, there is free online
ebook for it on internet. :-)

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 24 '07 #7
Thanks to you both

Got it working. Thanks very much, all of your information was very helpful
and has also given me a better understanding of VB.

Regards
ilr

"RobinS" wrote:
Here's an example from a posting I made back in November 2006 for
capturing and using the Format and Parse events on a DataGridView.

The OP was trying to change how the data is displayed, but
not how it's stored, so if the user puts in "75000", he wanted
it displayed as "75K", but stored as 75000. And when it's
brought in from the database, he wanted to convert it from
75000 to 75K. When it's put back, he wanted to translate it
the other way.

CellFormatting happens between the data source and the screen.
CellParsing happens between the screen and the data source.

Try this:

AddHandler myGrid.CellFormatting, AddressOf OnCellFormatting
AddHandler myGrid.CellParsing, AddressOf OnCellParsing

Private Sub OnCellFormatting(ByVal object as Sender, _
ByVal e as DataGridViewCellFormattingEventArgs)

If e.ColumnIndex = myGrid.Columns("columnIcareAbout") Then
'setting this to true signals the grid that this
' column is being dynamically updated. If you don't
' do this, you will get an infinite loop if you have
' also set the column to have its size automatically
' determined.
e.FormattingApplied = True

'get the row being populated; format this cell
Dim row as DataGridViewRow = myGrid.Rows(e.RowIndex)
If e.Value = "75000" Then
e.Value = "75K"
End If
End If
End Sub

Private Sub OnCellParsing(ByVal object as Sender, _
ByVal e as DataGridViewCellParsingEventArgs)

If e.ColumnIndex = myGrid.Columns("columnIcareAbout") Then
'get the row being populated; format this cell
Dim row as DataGridViewRow = myGrid.Rows(e.RowIndex)
If e.Value = "75K" Then
e.Value = "75000"
End If
End If
End Sub

Hope this helps.
Robin S.
-------------------
""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:BX**************@TK2MSFTNGHUB02.phx.gbl...
Hi Ian,

Thanks for your feedback.

I originally provided some sample code regarding using
Binding.Parse/Format
events in the link below, for your information:
http://groups.google.com/group/micro...rk.windowsform
s.databinding/msg/a429f83e8a552123?hl=en&

Also, the article I provided in the last reply also contains sample
code in
VB.net regarding how to use Binding.Parse/Format events:
"Data binding concepts in .NET windows forms"
http://www.codeproject.com/vb/net/da...ngconcepts.asp

I can not find a dedicate article regarding the usage of
DataGridView.CellParsing/CellFormatting events. Basicly, you may
select
DataGridView control in the VS2005 designer and click the event icon
in the
PropertyBrowser and find CellParsing/CellFormatting events in the
event
list. Then you may double click to add an event handler for these 2
events.

Below is the official link for DataGridView.CellParsing event, which
contains the most useful guidelines and sample code regarding its
usage:
http://msdn2.microsoft.com/en-gb/lib...datagridview.c
ellparsing.aspx

Anyway, if you still have any problem of getting this work for you,
please
feel free to tell me, I will work with you, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each
follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach
the
most efficient resolution. The offering is not appropriate for
situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are
best
handled working with a dedicated Microsoft Support Engineer by
contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.


Jan 24 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ben R. | last post by:
I've got a repeater that's bound to a datareader and I'd like to conditionally modify the text that is being outputted. Previously, I've done this by assigning a name to attribute to the...
1
by: Patrick Demets | last post by:
I have a fairly simple form with databound text boxes, but changes (or new records) are not recognized. The text boxes are successfully populated with data (from the database) and I can cycle...
9
by: Protoman | last post by:
Why doesn't this display the string? string decrypt(const string& ciphertext,const string& key) { string decrypted; decrypted.resize(ciphertext.size()); // allocates the string for the correct...
3
by: Felix_WafyTech | last post by:
Hi, I would like to create something similar to "The Code Project" message thread. You can see what I'm trying to explain by clicking on the link below: ...
5
by: clickon | last post by:
This is driving me nuts, it is such a simply thing to do but i cannot for the life of me work out how you are suposed to do it. I want to update the data in DropDownListB based on what is...
5
by: Stephen | last post by:
Hi, Is there anyway I can make a column thats databound into a hyperlink to navigate to another page? Suppose I have 3 columns: SortOrder, Description, UserName for eg: <Columns>...
7
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
4
by: parsifal | last post by:
Hi everyone :-) I am learning to use the Repeater control to display a list of data. Each of my list items (or rows, however you look at it) has some child items that are 1..N in length. So I'd...
4
by: seth_hickel | last post by:
With other solutions I would get a recordset, read each record and display data by formating my html as I wanted to display values of each record. I am trying to display data in a three column...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.