title: Default implementation for ListView OwnerDraw
body: <p>I have a <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.aspx" rel="noreferrer">ListView</a> where I wish to tweak the drawing of items (for example highlighting certain strings in list view itmes), however I don't want to radically alter the way that items are displayed.</p>
  
  <p>I have set the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.ownerdraw.aspx" rel="noreferrer">OwnerDraw</a> to true and can get my head around how to draw my highlighting effect, however whenever I try to defer to the default implementation to draw the rest of the list view item things go wrong and I'm left with a whole load of graphical problems indicating that actually I've completely gone wrong.</p>
  
  <p>Is there somewhere that I can see what the "Default" handlers for the <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.drawitem.aspx" rel="noreferrer"><code>DrawItem</code></a> and <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.listview.drawsubitem.aspx" rel="noreferrer"><code>DrawSubItem</code></a> events do so that I can better my understanding and more easily tweak my code?</p>
  
  <p>For reference here is a snippet showing what I'm currently doing:</p>
  
  <pre><code>public MyListView()
  {
      this.OwnerDraw = true;
      this.DoubleBuffered = true;
      this.DrawColumnHeader += new DrawListViewColumnHeaderEventHandler(MyListView_DrawColumnHeader);
      this.DrawItem += new DrawListViewItemEventHandler(MyListView_DrawItem);
      this.DrawSubItem += new DrawListViewSubItemEventHandler(MyListView_DrawSubItem);
  }
  
  private void MyListView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
  {
      // Not interested in changing the way columns are drawn - this works fine
      e.DrawDefault = true;
  }
  
  private void MyListView_DrawItem(object sender, DrawListViewItemEventArgs e)
  {
      e.DrawBackground();
      e.DrawFocusRectangle();
  }
  
  private void MyListView_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
  {
      string searchTerm = "Term";
      int index = e.SubItem.Text.IndexOf(searchTerm);
      if (index &gt;= 0)
      {
          string sBefore = e.SubItem.Text.Substring(0, index);
  
          Size bounds = new Size(e.Bounds.Width, e.Bounds.Height);
          Size s1 = TextRenderer.MeasureText(e.Graphics, sBefore, this.Font, bounds);
          Size s2 = TextRenderer.MeasureText(e.Graphics, searchTerm, this.Font, bounds);
  
          Rectangle rect = new Rectangle(e.Bounds.X + s1.Width, e.Bounds.Y, s2.Width, e.Bounds.Height);
          e.Graphics.FillRectangle(new SolidBrush(Color.Yellow), rect);
      }
  
      e.DrawText();
  }
  </code></pre>