JEFFCECCHINI
asked on
How to have the entire row of a DataGrid have a colored background when a cell in that row is selected?
My question applies to VB.NET:
How to have the entire row of a DataGrid have a colored background when a cell in that row is selected?
Thanks, Jeff
How to have the entire row of a DataGrid have a colored background when a cell in that row is selected?
Thanks, Jeff
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can set the grid's .SelectionBackColor at design time in the Properties (bottom right of the screen in a normal VB.NET IDE layout). If you want to change it in code it would be
DataGrid1.SelectionBackCol or = System.Drawing.Color.Blue 'or whatever you want
Once you've typed as far as System.Drawing.Color. a popup should appear with all the choices in it.
As for selecting the whole row with a non-mouse selection of a cell, it will need a different approach. I need to think about it and it's past my bedtime (1am in the UK, where I am). I hope you'll forgive me if I put that off until the morning. Or someone else might answer in the meantime.
Roger
DataGrid1.SelectionBackCol
Once you've typed as far as System.Drawing.Color. a popup should appear with all the choices in it.
As for selecting the whole row with a non-mouse selection of a cell, it will need a different approach. I need to think about it and it's past my bedtime (1am in the UK, where I am). I hope you'll forgive me if I put that off until the morning. Or someone else might answer in the meantime.
Roger
ASKER
Hi Roger,
Thanks for your help. Your example sparked some things in my brain. :-) It showed me how to select a row and from your example I applied other knowledge and got exactly what I wanted. FYI, here's what I did which works both for mouse cell selection and arrow cell selection of a row.
Private Sub DataGrid1_CurrentCellChang ed(ByVal sender As Object, ByVal e As System.EventArgs) Handles _ DataGrid1.CurrentCellChang ed
DataGrid1.Select(DataGrid1 .CurrentRo wIndex)
'DataGrid1.SelectionBackCo lor = System.Drawing.Color.Red 'Does not work because I have a tablestyle
DataGrid1.TableStyles(0).S electionBa ckColor = System.Drawing.Color.Green
End Sub
Thanks for your help. Your example sparked some things in my brain. :-) It showed me how to select a row and from your example I applied other knowledge and got exactly what I wanted. FYI, here's what I did which works both for mouse cell selection and arrow cell selection of a row.
Private Sub DataGrid1_CurrentCellChang
DataGrid1.Select(DataGrid1
'DataGrid1.SelectionBackCo
DataGrid1.TableStyles(0).S
End Sub
ASKER
Thanks for the quick response.
Could you write the line of code that defines the color? I just don't know what to do exactly.
And, I was wondering if the user used the up/down arrow keys to go from row to row, how would I accomplish the same end result, I tried to copy this into the DataGrid1_CurrentCellChang
Thanks, Jeff