DTGridView icon indicating copy to clipboard operation
DTGridView copied to clipboard

Cells in last row never get requested

Open mbarlocker opened this issue 15 years ago • 2 comments

I've got a grid 4 columns by R rows. I'm filling this grid with data such that each row might be only partially filled - 3 out of the 4 columns for example. Only 2 rows are on screen at any time (except during scrolling). It is a normal DTGridView that scrolls vertically.

The problem occurs when I have 4 rows. The first 3 are completely full (4/4 columns), and the last row is only partially full (1/4 columns). The DTGridView allows me to scroll to the 4th row, but the cell in the 4th row, 1st column never appears. I put logging statements in the gridView:viewForRow:column: method, and the cell is never even asked for.

Here's my pseudo code

  • (NSInteger)numberOfRowsInGridView:(DTGridView *)gridView { NSUInteger itemCount = ; return ceil((double)itemCount / (double)GRID_VIEW_NUM_VISIBLE_COLUMNS); }

  • (NSInteger)numberOfColumnsInGridView:(DTGridView *)gridView forRowWithIndex:(NSInteger)index { NSUInteger itemCount = ; NSUInteger rows = [self numberOfRowsInGridView:gridView]; NSUInteger numItemsIfFilled = GRID_VIEW_NUM_VISIBLE_COLUMNS * rows; BOOL lastRow = (index == rows - 1); BOOL gridFull = itemCount == numItemsIfFilled;

    NSInteger columns = GRID_VIEW_NUM_VISIBLE_COLUMNS;

    if (lastRow && !gridFull) { columns = itemCount % GRID_VIEW_NUM_VISIBLE_COLUMNS; }

    return columns }

  • (CGFloat)gridView:(DTGridView *)gridView heightForRow:(NSInteger)rowIndex { return gridView.frame.size.height / GRID_VIEW_NUM_VISIBLE_ROWS; }

  • (CGFloat)gridView:(DTGridView *)gridView widthForCellAtRow:(NSInteger)rowIndex column:(NSInteger)columnIndex { return gridView.frame.size.width / GRID_VIEW_NUM_VISIBLE_COLUMNS; }

  • (DTGridViewCell *)gridView:(DTGridView *)gridView viewForRow:(NSInteger)rowIndex column:(NSInteger)columnIndex { return ; }

One thing to note is that when the number of rows fits on screen, the last row shows just fine. It is only when the last row does not fit on screen that it is not requested at all.

mbarlocker avatar Jan 29 '11 16:01 mbarlocker

For the time being, I am just going to always return 4 columns, and then when the cell is requested, I will return an uncustomized DTGridViewCell. This seems to work.

mbarlocker avatar Jan 29 '11 16:01 mbarlocker

Any updates regarding this issue?

anjerodesu avatar Dec 20 '11 08:12 anjerodesu