title: (C#) DataGridView: How to get Selected Count with cells AND rows?
body: <p>So I have this <a href="https://i.stack.imgur.com/YFMc1.png" rel="nofollow noreferrer">DataGridView</a></p>
  
  <p>And This code:</p>
  
  <pre><code>if(dataGridView1.SelectedRows.Count &gt; 1)
          {
              MessageBox.Show("Error: More than one value selected");
              return false;
          }
  </code></pre>
  
  <p>It counts correctly to 2 if I have 2 completly selected rows.
  But I want to check if <strong>any cells</strong> from 2 different rows or more are selected.</p>
  
  <p>In other words:
  <strong>in my picture</strong> my current selection is returning 1 at the moment but i want it to return 2.</p>
  
  <p>Thank you.</p>
  
  <p>Edit after fix: Working code:</p>
  
  <pre><code>if(dataGridView1.SelectedCells.Cast&lt;DataGridViewCell&gt;().Select(c =&gt; c.RowIndex).Distinct().Count() &gt; 1)
          {
              MessageBox.Show("Error: More than one value selected");
              return false;
          }
  </code></pre>