Resolved DataGridView & Selected Row

ALX

Well-known member
Joined
Nov 16, 2005
Messages
253
Location
Columbia, SC
Programming Experience
10+
In a DataGridView where the Selection Mode is set to Full Row Select, single row selection and the row's DefaultSelectionBack Color is set to a particular color, the user becomes accustomed to seeing this selected Row's backcolor when they click on a row. If they are clicking the row with the Control Key however, the DataGridView will not set this backcolor. It does select the Row, as the row's data is loaded on another control, but the lack of background color leads the user to believe that the row is not actually selected. Is there a way to force the DGV to treat this as an ordinary selected row by using the selected backcolor even when the user is holding the Control key. I know this sounds trivial, but I'm trying to fool proof this app.
 
Last edited:
I could not reproduce it for a DataGridView with those three properties set:
VB.NET:
Dim dgv = New DataGridView
With dgv
    .SelectionMode = DataGridViewSelectionMode.FullRowSelect
    .MultiSelect = False
    .DefaultCellStyle.SelectionBackColor = Color.Red
    .RowCount = 5
    .ColumnCount = 2
End With
Controls.Add(dgv)
 
As always, John, I appreciate your taking the time to look at this.
Initially I was setting the Row's selection in code, as in "CDGV(Column, Row).Selected = True" so that the row would be selected regardless of Modifier keys or Right Click, etc.
So the user's click would select the row and my code would be like a repeated click to the same row, so since it was with the Control modifier it immediately deselected the Row.
If I had posted my code you would have caught that. I should have known better, and I promise to post my code in the future whether I think it will help or not !
Once I got rid of the extra Row Selection that I induced thru the code, I still had the problem of the Row becoming deselected if the user clicked it again with the Ctrl key. It turns out that I can solve that issue by clearing the DataGridView's Selection - as in - "DGV.ClearSelection()". The system then reselects the row as if it where the 1st click to that Row. 'Just a little flicker and then it is reselected. This way the active row is always selected and highlighted. Sorry to waste your time with this.
 
Last edited:

Latest posts

Back
Top