private Rectangle CalculateCellBounds(OLVListItem item, int subItemIndex, ItemBoundsPortion portion)
{
// SubItem.Bounds works for every subitem, except the first.
if (subItemIndex > 0)
return item.SubItems[subItemIndex].Bounds;
// For non detail views, we just use the requested portion
Rectangle r = this.GetItemRect(item.Index, portion);
if (r.Y < -10000000 || r.Y > 10000000) {
r.Y = item.Bounds.Y;
}
if (this.View != View.Details)
return r;
// Finding the bounds of cell 0 should not be a difficult task, but it is. Problems:
// 1) item.SubItem[0].Bounds is always the full bounds of the entire row, not just cell 0.
// 2) if column 0 has been dragged to some other position, the bounds always has a left edge of 0.
// We avoid both these problems by using the position of sides the column header to calculate
// the sides of the cell
Point sides = NativeMethods.GetScrolledColumnSides(this, 0);
r.X = sides.X + 4;
r.Width = sides.Y - sides.X - 5;
return r;
}