current_x += column->width;
  
 -      if (x >= event->area.x && x < event->area.x + event->area.width)
 -        gdk_draw_line (event->window,
 -                       tree_view->priv->grid_line_gc[GTK_WIDGET(tree_view)->state],
 -                       x, min_y,
 -                       x, max_y - min_y);
+       /* Generally the grid lines should fit within the column, but for the
+          last visible column we put it just past the end of the column.
+          (Otherwise horizontal grid lines sometimes stick out by one pixel.) */
+       x = current_x;
+       if (i != n_visible_columns - 1)
+         x--;
+ 
-       cairo_move_to (cr, current_x - 0.5, min_y);
-       cairo_line_to (cr, current_x - 0.5 , max_y - min_y);
-       
 +      cairo_set_line_width (cr, 1.0);
 +      cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
++      cairo_move_to (cr, x + 0.5, min_y);
++      cairo_line_to (cr, x + 0.5, max_y - min_y);
 +      cairo_stroke (cr);
      }
  }
  
  
          if (draw_hgrid_lines)
            {
 -            if (background_area.y > 0)
 -              gdk_draw_line (event->window,
 -                             tree_view->priv->grid_line_gc[widget->state],
 -                             background_area.x, background_area.y,
 -                             background_area.x + background_area.width,
 -                             background_area.y);
 -
 -            if (y_offset + max_height <= event->area.height)
 -              gdk_draw_line (event->window,
 -                             tree_view->priv->grid_line_gc[widget->state],
 -                             background_area.x, background_area.y + max_height,
 -                             background_area.x + background_area.width,
 -                             background_area.y + max_height);
 +            cairo_set_line_width (cr, 1.0);
 +            cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
 +
 +            if (background_area.y >= 0)
 +              {
 +#if GTK3_TRANSITION
 +                gdk_draw_line (event->window,
 +                               tree_view->priv->grid_line_gc[widget->state],
 +                               background_area.x, background_area.y,
 +                               background_area.x + background_area.width,
 +                               background_area.y);
 +#else
 +                cairo_move_to (cr, background_area.x, background_area.y - 0.5);
 +                cairo_line_to (cr, background_area.x + background_area.width,
 +                               background_area.y - 0.5);
 +#endif
 +              }
 +
-             if (y_offset + max_height >= Zarea.height - 0.5)
++            if (y_offset + max_height <= Zarea.height - 0.5)
 +              {
 +#if GTK3_TRANSITION
 +                gdk_draw_line (event->window,
 +                               tree_view->priv->grid_line_gc[widget->state],
 +                               background_area.x, background_area.y + max_height,
 +                               background_area.x + background_area.width,
 +                               background_area.y + max_height);
 +#else
 +
 +                cairo_move_to (cr, background_area.x, background_area.y + max_height - 0.5);
 +                cairo_line_to (cr, background_area.x + background_area.width,
 +                               background_area.y + max_height - 0.5);
 +#endif
 +              }
 +            cairo_stroke (cr);
            }
  
            _pspp_sheet_view_column_cell_render (column,