Advanced Cell formatting - DataGridViewColumn

Using StringTo() method for Formatting cell within the DataGridViewColumn:

I have created custom DataGridViewColumn and DataGridViewCell based on user defined data type. It stores float numbers that represent various strings. For example number 0.001 represents string "00", number 1.002 is formatted as "1T", number 0.5 is "05" while integers are formatted as they are (100 => "100") etc. Override ToString() method is used to provide the conversion from a number to a string.

I now need to force my custom column to display the formatted strings instead of the float values that I stored in database, i.e. when I type 0.001 into the cell, I need to display "00" but the value of the cell must retain value 0.001. Usually I would do it using Format property of the Column.CellTemplate.Style but I have no idea how to do it when the format conversion can't be described by standard string like "0:00.00" or "$ #0.00" but is based on an overridden method defined in the user defined type. Any idea how to solve it and keep the column bounded to a data source and allow user to modify and store values through the same column?

[1217 byte] By [krejcimar] at [2007-12-23]
# 1
You can format the output of the CellFormat event and Convert it to database format in the CellParsing event.
KenTucker at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...
# 2

Thank you. I'd already found OnCellFormatting method that helped to solve the problem.

CellParsing is also a very good idea, I think I may use it for another problem, I had no idea how to proceed with. Thanks a lot.

krejcimar at 2007-8-30 > top of Msdn Tech,Windows Forms,Windows Forms Data Controls and Databinding...