Billy Coover
Billy Coover

Reputation: 3837

How to create a custom DataGridViewCell

I'm working on a grid view that will display cells that will have some controls inside of it. For example, a cell will have three or four labels and maybe a color picker. The values of those labels can be databound.

I'm assuming that I need to create a custom DataGridViewCell but I'm having a hard time finding documentation that talks about this type of custom cell. Most examples demonstrate how to extend a DataGridViewCell by using other types of DataGridViewCell's like DataGridViewImageCell.

Does anyone have an example of custom cell class that derives from DataGridViewCell?

Here is my horrible attempt at trying to draw this cell in paint.Net. Hopefully, after your done laughing, you'll get an idea of the custom cell I'm trying to build.alt text http://lh3.ggpht.com/_UxHcYyy8tU8/SgmTd1MqUOI/AAAAAAAAAnU/lO2bE7-gvpg/s800/DataGridViewCell.png

Upvotes: 1

Views: 3202

Answers (2)

Billy Coover
Billy Coover

Reputation: 3837

I thought about this more and I discovered my approach was wrong. The DataGridView has good support for adding user controls in edit mode but the view I'm creating is intended to be always interactive and is probably not appropriate for a DataGridView.

The solution that I came up with was to use a TableLayoutPanel. This control works great for me because you get so much control over how it is rendered and it is very easy to nest controls inside of it.

Perhaps the question I asked needs to be tweaked a little because the solution I'm excepting solves my problem but doesn't really answer the question.

Upvotes: 2

Billy Coover
Billy Coover

Reputation: 3837

If the cell view layout is static, perhaps hosting a user control in the cell is appropriate.

Upvotes: 1

Related Questions