Groups | Blog | Home
all groups > dotnet windows forms databinding > august 2006 >

dotnet windows forms databinding : Modify Values of databound textbox before they are stored in underlying DB



Grady Morgan
8/22/2006 1:21:51 PM
Instead of adding the binding using control.DataBindings.Add( "Text",
myObject, "Password" ), create a new Binding as follows:

Binding binding = new Binding( "Text", myObject, "Password" );
binding.Format += new ConvertEventHandler(Password_Format);
binding.Parse += new ConvertEventHandler(Password_Parse);

control.DataBindings.Add( binding );

void Password_Format( object sender, ConvertEventArgs e )
{
e.Value = DecryptPassword( e.Value );
}

Password_Parse would be similar to this.

-Grady

[quoted text, click to view]
Angelo Campitelli
8/22/2006 9:03:44 PM
Hi,

I have a db field that contains a password i would like to run a function to
decrypt the value before its returned to a bound textbox and before the
field is updated encrypt the contents.

Is there an easy way to bind a field but modify the contents as its being
passed to/returned from the underlying db?


AddThis Social Bookmark Button