views:

192

answers:

4

I'm creating my own very basic Grid control. I've decided to derive from ScrollableControl (this is what DataGridView seems to do) and go from there.

I have a lot of code in place to draw my cells, but I am having difficulty figuring out how to utilize the "scrollable" part of the ScrollableControl. It seems that ScrollableControl's designed to be a container of other controls, and it's "auto" scrolling features are oriented around child controls that are outside the bounds of the control.

I'm just looking to set the "virtual" area of the control so I get scroll bars of the correct size, then I do my own drawing into the control to create my own "view".

I'm basically very frustrated by this. What's the simplest way to get this to work?

A: 

As far as I know, you would need to have some child of ScrollableControl positioned at the lower-right bounds of your virtual surface. Perhaps a PictureBox with a 1 pixel transparent image would do.

FYI you may want to look at SourceGrid, either as a design inspiration (it makes good use of the MVC pattern), or perhaps it will solve your problem and you will not want to roll your own.

EDIT: Doh! I'm pretty sure Michael's solution is correct/better. However you may still want to have a look at SourceGrid.

Eric J.
+1  A: 

You have to set the AutoScrollMinSize property to tell the control what area you intend to render.

Michael McCloskey
I get it now. Wow, that's pretty non-intuitive. MinSize is actually it's max size... or rather the size of the virtual area...
Mystere Man
I couldn't agree more about the naming. One certainly wouldn't guess that's what it does from the name.
Michael McCloskey
A: 

You could just dump it into a Panel with Scrollbars :)

tsilb
A: 

Not to be flip, The level of customization you are seeking is much more appropriate and future-proof in WPF. It is possible to build your control and host it in WinForms if forklifting your app is out of the question.

Jerry Bullard
Two problems. My code has to work on Windows 2000, WPF doesn't work on Win2k and I don't have the time to invest in learning WPF right now.
Mystere Man