title: Total cell count of a DataGridView
body: <p>I need to get the total number of cells that are present in a datagridview.  This is then used to determine if I want to include the column header text when copying/pasting the data, I only want this displayed if all records are selected. </p>
  
  <p>I am using the following code to get the total number of cells but is there a better way to get this value?</p>
  
  <pre><code>var totalCellCount = DataGridView2.ColumnCount * DataGridView2.RowCount;
  </code></pre>
  
  <p>I couldn't find a property that contained a count of all cells, maybe I am missing it.  Is there a better way to get the number of cells?</p>
  
  <p>My datagridview has the <code>ClipboardCopyMode</code> set to <code>EnableWithAutoHeaderText</code>, but I want to set it to <code>EnableAlwaysIncludeHeaderText</code> when they select all rows/columns in the grid.  So I am using the total number of cells in the code below:</p>
  
  <pre><code>private void DataGridView_KeyPress(object sender, KeyPressEventArgs e)
  {
       if (m_RecordCount == 0)
       return;
  
        var totalCellCount = DataGridView2.ColumnCount * DataGridView2.RowCount;
  
        if (DataGridView2.SelectedCells.Count == totalCellCount)
        {
            if (e.KeyChar == (char)3)
            {
              DataGridView2.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
              var clipboardContent = this.DataGridView2.GetClipboardContent();
  
              if (clipboardContent != null)
              {
                  Clipboard.SetText(clipboardContent.GetText(TextDataFormat.Text));
              }
              e.Handled = true;
             }
         }
     }  
  </code></pre>