How to disable Cell Highlighting in a datagridview, Highlighting should not happen even if I click on the cell.
Any thoughts please
Private Sub DGW2_DataBindingComplete(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewBindingCompleteEventArgs) Handles DGW2.DataBindingComplete
Dim mygrid As DataGridView
mygrid = CType(sender, DataGridView)
mygrid.ClearSelection()
End Sub
The quickest way to do this to handle cells with different colours, without needing to refire any events, would be to do something like this:
private void dgvMyControl_SelectionChanged(object sender, EventArgs e)
{
dgvMyControl.SelectedCells(0).Style.DefaultCellStyle.SelectionBackColor = dgvMyControl.SelectedCells(0).Style.DefaultCellStyle.BackColor
}
(EDIT)
actually, this needs to be done at time for data population. it doesn't appear to work in the on selection changed method. So after populating the data into the table, you need to iterate through the cells and change their selected background to match their normal background. Something like this (syntax may be a little off, I'm converting it from my vb code):
foreach (datarow r in dgv.rows)
{
foreach (datacell c in r.cells)
{
c.Style.SelectionBackColor = c.Style.BackColor
}
}
Messing around and this also works, as i only want to change the cell background colour in the 2nd column when a cell is clicked:
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim row As Integer = DataGridView1.CurrentCellAddress.Y
Dim column As Integer = DataGridView1.CurrentCellAddress.X
If column = 1 Then
Me.DataGridView1.CurrentCell.Selected = False
DataGridView1.Item(column, row).Style.BackColor = SelectColour()
End If
End Sub
<DataGrid ItemsSource="{Binding Credits}" x:Name="Grid"
HorizontalAlignment="Left" RowBackground="Transparent">