title: Multiselect in DataGridview without the control key (also changing font color of selected item)
body: <p>How to <code>Multiselect</code> in <code>DataGridView</code> without having to press control key (only by mouse click) and change the fontcolor of all the selected row to red when selected and black when unselected. I'm using vb.net Thank you</p>
  
  <hr>
  
  <p>Found the solution to my problem. Hope this help:</p>
  
  <p>I use the CellClick and RowPrePaint of DataGridView</p>
  
  <pre><code>Private Sub dgvUDF_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvUDF.CellClick
          If (Me.selectedRowIndexes.IndexOf(e.RowIndex) &gt; -1) Then
              Me.selectedRowIndexes.Remove(e.RowIndex)
          Else
              Me.selectedRowIndexes.Add(e.RowIndex)
              Me.dgvUDF.CurrentCell = Nothing
          End If
  End Sub
  
  Private Sub dgvUDF_RowPrePaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles dgvUDF.RowPrePaint
          If (Me.selectedRowIndexes.IndexOf(e.RowIndex) &gt; -1) Then
              dgvUDF.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Crimson
          Else
              dgvUDF.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
          End If
      End Sub
  </code></pre>