Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Changing background color of datagrid cells in vb.net

Changing background color of datagrid cells in vb.net

Scheduled Pinned Locked Moved Visual Basic
csharptutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Silver Grey
    wrote on last edited by
    #1

    Can anybody show me how to change the background of selected datagrid cells Thanks

    silver-gray

    J 1 Reply Last reply
    0
    • S Silver Grey

      Can anybody show me how to change the background of selected datagrid cells Thanks

      silver-gray

      J Offline
      J Offline
      jsampsonPC
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • J jsampsonPC

        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

        S Offline
        S Offline
        Silver Grey
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • S Silver Grey

          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

          J Offline
          J Offline
          jsampsonPC
          wrote on last edited by
          #4

          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

          S 1 Reply Last reply
          0
          • J jsampsonPC

            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

            S Offline
            S Offline
            Silver Grey
            wrote on last edited by
            #5

            WHAT DO YOU MEAN YOU IGNORE AND KEEP TYPING?? can you show me what it is you are typing ?? Thanks

            silver-gray

            J 1 Reply Last reply
            0
            • S Silver Grey

              WHAT DO YOU MEAN YOU IGNORE AND KEEP TYPING?? can you show me what it is you are typing ?? Thanks

              silver-gray

              J Offline
              J Offline
              jsampsonPC
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups