Changing background color of datagrid cells in vb.net
-
Can anybody show me how to change the background of selected datagrid cells Thanks
silver-gray
-
Can anybody show me how to change the background of selected datagrid cells Thanks
silver-gray
The answer you seek rests within the DataGridViewColumn.DefaultCellStyle.BackColor class. Enjoy! Here's an example I wrote up:
For Each dgvc As DataGridViewColumn In dgvTableList.Columns
If dgvc.HeaderText = "name" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells ElseIf dgvc.HeaderText = "crdate" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill dgvc.DefaultCellStyle.BackColor = Color.Aquamarine Else dgvc.Visible = False End If
Next
Jonathan Sampson www.SampsonResume.com
-
The answer you seek rests within the DataGridViewColumn.DefaultCellStyle.BackColor class. Enjoy! Here's an example I wrote up:
For Each dgvc As DataGridViewColumn In dgvTableList.Columns
If dgvc.HeaderText = "name" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells ElseIf dgvc.HeaderText = "crdate" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill dgvc.DefaultCellStyle.BackColor = Color.Aquamarine Else dgvc.Visible = False End If
Next
Jonathan Sampson www.SampsonResume.com
Is your reply for 2005?? I have 2003. my 2003 does not know what this is "DataGridViewColumn" What is the solution in 2003 Thanks
silver-gray
-
Is your reply for 2005?? I have 2003. my 2003 does not know what this is "DataGridViewColumn" What is the solution in 2003 Thanks
silver-gray
Um, I don't know what a .NET1.1 solution would be. Sorry. For what it's worth, my VS2005 Intellisense doesn't pick up "DataGridViewColumn" either. I just ignore the intellisense and keep typing - the code works, but intellisense won't display "DataGridViewColumn" as a class under the namespace.
Jonathan Sampson www.SampsonResume.com
-
Um, I don't know what a .NET1.1 solution would be. Sorry. For what it's worth, my VS2005 Intellisense doesn't pick up "DataGridViewColumn" either. I just ignore the intellisense and keep typing - the code works, but intellisense won't display "DataGridViewColumn" as a class under the namespace.
Jonathan Sampson www.SampsonResume.com
WHAT DO YOU MEAN YOU IGNORE AND KEEP TYPING?? can you show me what it is you are typing ?? Thanks
silver-gray
-
WHAT DO YOU MEAN YOU IGNORE AND KEEP TYPING?? can you show me what it is you are typing ?? Thanks
silver-gray
Calm down, no need for caps - I'm trying to help you here :) I coded this, and it worked as you requested.
For Each dgvc As DataGridViewColumn In dgvTableList.Columns
If dgvc.HeaderText = "name" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells ElseIf dgvc.HeaderText = "crdate" Then dgvc.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill dgvc.DefaultCellStyle.BackColor = Color.Aquamarine Else dgvc.Visible = False End If
Next
If that code doesn't work for you, I'm unable to help you any further as I have no experience with .NET prior to the 2.0 Framework.
Jonathan Sampson www.SampsonResume.com