More than one way to skin a cat…

Needed to display some data in a grid. No biggie. But I wanted some custom formatting — mainly allowing for links and whatnot. Eventually, I was left with two options — inheriting a richtextbox control and using that as a custom datagridcolumn or doing an override on a paint event for the cell…

Started with the richtextbox method, but it seemed like the only way that worked was if the editing control was overridden… Not much use for displaying the stuff. Meh.

So I tried out using the paint event. That actually worked pretty good at first. Using GDI+ DrawString calls to write what I wanted in the color/formatting I wanted — albeit in a somewhat clumsy way. But then I began running into issues when I had multiple strings needing formatting or if the string needed to wrap within the cell.

Deciding both method were way too complex for what I needed, I started rethinking the issue. What I really needed was a way to have it render HTML text. That way I could do some handy-wavy string manipulations to set the various tags I needed and that would be all that’s needed.

After looking around for a while for a simple way of doing that within the datagridview, I changed my design plan a bit…

That’s when I got an idea…

If I used a web browser control, I’d certainly have the HTML support I needed. And by using tables within HTML, I’d be able to get pretty close to the same grid feel as that original datagridview.

Share Your Thought