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?
You have to set the AutoScrollMinSize
property to tell the control what area you intend to render.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With