I am writing a .NET WinForms application that needs to display a list of results in a nice formatted user-friendly fashion. Here’s how I’m hoping to display the data.
alt text http://img398.imageshack.us/img398/4336/imgdyu.png
The table must support a decent amount of data(>= 200 individual “data blocks”), and needs to be fairly fast. I’m unsure of the easiest way to accomplish this and I was hoping for some direction and advice. I created a quick prototype custom control that simply used a bunch a text boxes stacked on top of each other. It worked fairly well but Windows runs out of handles for the textboxes too quickly. I could create a custom textbox control, but it would be time consuming and I was wondering if there are any recommendations for alternative solutions? Thanks.
You could use a third-party control for this (maybe), but here are some reasons why this is potentially a bad idea:
For anything out of the ordinary (like what you’re doing), writing your own UserControl is the best way to go, for these (among others) reasons:
Your particular problem (well described in your question, thanks to the graphics) is quite easy to do as a mostly owner-drawn UserControl (with a TextBox or two thrown in the mix). The only methods you’ll need from the System.Drawing.Graphics object are DrawRectangle, FillRectangle, MeasureString and DrawString. You won’t even need any documentation, as Intellisense will give you everything you need.
If you run into trouble, I’ll write it for you for a chocolate chip cookie. 🙂
Update: since you need the text to all be selectable, that makes this approach a bit more complicated. Implementing your own Textbox-type functionality is a gigantic pain in the petard, but a relatively simple solution is to add a real multi-line Textbox over top of any text-containing rectangle when the user clicks on it, and to put the rectangle’s text (pre-selected) into the Textbox. When this temporary Textbox loses focus (LostFocus), you draw the edited text into the rectangle and delete the Textbox. This way you only have one Textbox at a time in your UserControl.
This version will cost you two cookies.
Update 2: Here is a simple application that demonstrates how to use a single TextBox to make your entire control selectable and editable. And here is the source code.