views:

317

answers:

2

I am using a DataGridView with a DataTable as a stack for some values. Something gets recorded into the DataTable rows and then I send them somewhere in a FIFO fashion - it would be very nice to draw the rows in a bottom->up(to stack them up) direction instead of a up->down direction.

How can I achieve this since the paint events are only usefull for painting cells/single rows?

A: 

I am sorry, I was a bit unclear (I wasnt sure if it is bottom-alligned or bottom-docked or whatever so I left out that part).

But, nevertheless I figured it out. It seems that the CellPainting event isnt constrained to the cell boundaries so you can simply move the cell bounding rectangle, like this:

Rectangle^ newRect = gcnew Rectangle(
    e->CellBounds.X, 
    DataGridView->Bounds.Bottom-e->CellBounds.Y, // this is the moving part
    e->CellBounds.Width,
    e->CellBounds.Height
);

There are some minor modifications to be considered (if the bottom scrollbar is visible, the DataGridView boundaries) but the code captures the point.

Looking at the problem from a distance sure does the trick ;)

Edit: Yes indeed, this draws the cells bottoms up BUT it also makes some funky effects on vertical/horizontal scrolling and window focus change. And yes, no header cells. Back to the drawing board.

Ezekiel Rage
I don't expect this is going to work. Have you tried with a vertical scrollbar visible? (Among a lot of other objections).
Henk Holterman
Yes - both are visible - vertical and horizontal. The funny thing is that a custom cell paint event works without any trouble if you keep the original orientation.
Ezekiel Rage
A: 

Write a custom stack that uses dummy object for empty slots in the stack. The dummy object can be a static object with empty properties. As you fill the stack remove the dummy object and add your new item there. Then use this stack as binding source. The dummy objects at the end of the stack ensure that the first/top rows in the DataGridView Cells are empty. This way you don't need to bother modifying DataGridView behavior.

Vivek
This was the best (and least complicated) approximation to the behaviour I wanted.
Ezekiel Rage