title: MouseHover Event on DataGridView - Index Out of Range
body: <p>I have a <a href="/questions/tagged/winforms" class="post-tag" title="show questions tagged &#39;winforms&#39;" rel="tag">winforms</a> application with a <code>DataGridView</code>, and have been trying to set up a <code>MouseHover</code> event which provides some more detailed information about the cell being hovered over.</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>private void dataCaseHistory_MouseHover(object sender, EventArgs e)
  {
      try
      {
          DataGridView grid = (DataGridView)sender;
          Point clientPos = grid.PointToClient(Control.MousePosition);
          DataGridViewCell cell = (DataGridViewCell)grid[clientPos.X, clientPos.Y];
          int cellRow = cell.RowIndex;
          int cellColumn = cell.ColumnIndex;
  
          DataTable table = (DataTable)dataCaseHistory.DataSource;
          int docColumn = table.Columns.IndexOf("Doc");
          if (cellColumn == docColumn)
          {
              var varBundleID = table.Rows[cellRow]["BundleID"];
              if (varBundleID != DBNull.Value &amp;&amp; varBundleID != null)
              {
                  int bundleID = (int)varBundleID;
                  cBundle bundle = new cBundle(bundleID);
                  string header = "Bundle: '" + bundle.Name + "'";
                  string body = "";
                  foreach (DataRow row in bundle.DocumentBundle.Rows)
                  {
                      int docID = (int)row["DocumentID"];
                      cDocument doc = new cDocument(docID);
                      body += doc.DocumentName + Environment.NewLine;
                  }
                  MessageBox.Show(body, header);
              }
              else
              {
                  var varDocID = table.Rows[cellRow]["DocID"];
                  if (varDocID != DBNull.Value &amp;&amp; varDocID != null)
                  {
                      int docID = (int)varDocID;
                      cDocument doc = new cDocument(docID);
                      string header = "Document";
                      string body = doc.DocumentName;
                      MessageBox.Show(body, header);
                  }
              }
          }                
      }
      catch (Exception eX)
      {
          string eM = "Error occurred when Single Clicking a Document link in the History tab";
          aError err = new aError(eX, eM);
          MessageBox.Show(eX.Message, eM);
      }
  }
  </code></pre>
  
  <p>But I get an index out of range error as soon as the form loads and whenever I move my mouse.  I've never used this event before, so I'd be most appreciative if someone could point out where I am going wrong.</p>