views:

199

answers:

2

Is there any way to embed a widget in a data-bound DataGridViewCell when it is not in editing mode?

For example, we are wanting to display an existing calendar widget in a cell. That cell contains a comma separated list of dates. We want to show the calendar instead of the text.

We could create a custom cell and override the Draw method so that it draws the calendar in the cell, but that would not handle the mouse-over tool-tip that we already have in the existing calendar widget.

[Update] I tried TcKs's suggestion, but was not able to create a working solution. See the comments on that answer.

A: 

You can instead of drawing calendar, take a calendar control, set them the grid as parent and set them same bounds ( left, top, width, height ) as cell has.

TcKs
Thanks for the suggestion, but but I was unable to make it work.For the sake of example I created a button. I set the parent to the grid view, I set the bounds to the cell's ContentBounds, I even call BringToFont on the button. Even if set the top/left to 0,0 it still does not show on the grid.
Robert Gowland
+1  A: 

You should derive your own type from DataGridViewColumn (e.g. a DataGridViewCalendarColumn) and return a DataGridViewCalendarCell (that you have to create yourself, too) as the CellTemplate.
A detailed description can be found in the MSDN article Build a Custom RadioButton Cell and Column for the DataGridView Control

EFrank
Thank you very much for this answer. This isn't exactly what I was after (it still relies on overriding the Paint method rather than actually embedding a widget), but it is as close as I have been able to find.
Robert Gowland