Google Ads

Thursday, September 21, 2006

Handy Binder Formatter and Parser

This is a very old tricks. However it spend me a little time to get it back to my memory.

What is it for?

When we doing custom binding with a textbox or any string fields we always like to change the format to our desire pattern for example a money value in the database is 19 but we want to display it as $19.00 in our User friendly UI

We can add this binding tricks.

Implementation:

Databind()

{

      Binding dobinding = new Binding("Text", MyObject, "");

      dobinding += new ConvertEventHandler(doBinding_Format);

      dobinding += new ConvertEventHandler(doBinding_Parse);

      textBoxABC.DataBindings.Add(dobinding);

}

and then you just need to handle the event object and change it to return the output format.

you don't always need to do both Format and Parse, if you doing one way binding just for display.

 

Cheers,

Gary.


0 comments: