views:

520

answers:

0

Hi,

I'm trying to use and modify the code behind the TreeGridView control created by Mark Rideout and explained here:

http://blogs.msdn.com/markrideout/archive/2006/01/08/510700.aspx

My current problem is that I want to have non-data bound checkboxes in certain cells. It didn't seem to work to use a DataGridViewCheckBoxColumn, so I thought I should implement some custom classes deriving from DataGridViewCell and DataGridViewColumn.

I've got this far: I have a CheckBoxCell class which derives from DataGridViewCell. This class owns a System.Windows.Forms.CheckBox. I have overrided the Clone- and Paint methods and some problems I had made me also add an overriding of the FormattedValueType property. - My current problem has to do with this property. I'm not sure what it should be.

Right now I'm just returning a bool as FormattedValueType, and in the Paint method I'm passing the Checkbox object as 'value' parameter and the Checkbox's checked property as 'formattedValue' parameter (to the base class' Paint method).

When I try to run the code I get this exception: "System.FormatException: Formatted value of the cell has a wrong type."

It would be great if someone could help me with this problem. I think the most important questions are: What should the FormattedValueType be? and
What else do I need to write to be able to paint the checkbox cells and use them in a normal checkbox fashion?

(Additional info: My class that derives from DataGridViewColumn currently only has a Clone method and a constructor where the CellTemplate is set to an instance of my CheckboxCell.)

Please help!

/Ylva