Custom DataGridViewCell data binding question.
-
I have created a custom datagridviewcell that is to take a double value from the database and parse it into a string that displays a date in a certain format. I have the conversion process working. The trouble that I am having is getting and pushing the double value to/from the database. Of course the FormattedValue that is generally pushed to the database is the string but I want the double that generated the string. Any ideas on how I can change the property that is bound to the database instead of FormattedValue? Brian
-
I have created a custom datagridviewcell that is to take a double value from the database and parse it into a string that displays a date in a certain format. I have the conversion process working. The trouble that I am having is getting and pushing the double value to/from the database. Of course the FormattedValue that is generally pushed to the database is the string but I want the double that generated the string. Any ideas on how I can change the property that is bound to the database instead of FormattedValue? Brian
I figured it out. What I did was override the cell's Paint method and paint the string I wanted displayed in the cell leaving the double value as the cells formattedValue. I then overrode the cell's ParseFormattedValue method to take the string that the user input, convert it to the appropriate double representation and make it the formattedValue of the cell. This displayed the correct value to the user while maintaining the correct double value as the cells value for pushing back to the database. I also had to create a new DataGrodViewEditControl to display the correct string to the user when editing. If anyone has a similar problem and wants a look at the code, email me at liedtke@frii.com. Brian